Skip to content

Commit 41c49aa

Browse files
authored
refactor(cdk): simplify onStrategy error handling (#1371)
1 parent 2e94f9d commit 41c49aa

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

libs/cdk/render-strategies/src/lib/onStrategy.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgZone } from '@angular/core';
22
import { RxCoalescingOptions } from '@rx-angular/cdk/coalescing';
3-
import { switchMap, take } from 'rxjs/operators';
4-
import { Observable, of, throwError } from 'rxjs';
3+
import { Observable, throwError } from 'rxjs';
4+
import { catchError, map, take } from 'rxjs/operators';
55
import { RxRenderWork, RxStrategyCredentials } from './model';
66

77
/**
@@ -22,22 +22,16 @@ export function onStrategy<T>(
2222
) => void,
2323
options: RxCoalescingOptions & { ngZone?: NgZone } = {}
2424
): Observable<T> {
25-
let error: Error;
2625
return new Observable<T>((subscriber) => {
2726
subscriber.next(value);
2827
}).pipe(
2928
strategy.behavior({
30-
work: () => {
31-
try {
32-
workFactory(value, strategy.work, options);
33-
} catch (e) {
34-
error = e;
35-
}
36-
},
29+
work: () => workFactory(value, strategy.work, options),
3730
scope: (options.scope as Record<string, unknown>) || {},
3831
ngZone: options.ngZone,
3932
}),
40-
switchMap(() => (error ? throwError([error, value]) : of(value))),
33+
catchError((error) => throwError(() => [error, value])),
34+
map(() => value),
4135
take(1)
4236
);
4337
}

0 commit comments

Comments
 (0)