File tree Expand file tree Collapse file tree 2 files changed +23
-16
lines changed Expand file tree Collapse file tree 2 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -248,19 +248,18 @@ describe('EffectSources', () => {
248
248
it ( 'should resubscribe on error by default' , ( ) => {
249
249
class Eff {
250
250
@Effect ( )
251
- b$ = hot ( 'a--b--c --d' ) . pipe (
251
+ b$ = hot ( 'a--e-- b--e--c--e --d' ) . pipe (
252
252
map ( v => {
253
- if ( v == 'b ' ) throw new Error ( 'An Error' ) ;
253
+ if ( v == 'e ' ) throw new Error ( 'An Error' ) ;
254
254
return v ;
255
255
} )
256
256
) ;
257
257
}
258
258
259
259
const sources$ = of ( new Eff ( ) ) ;
260
260
261
- // 👇 'b' is ignored.
262
- const expected = cold ( 'a-----c--d' ) ;
263
-
261
+ // 👇 'e' is ignored.
262
+ const expected = cold ( 'a-----b-----c-----d' ) ;
264
263
expect ( toActions ( sources$ ) ) . toBeObservable ( expected ) ;
265
264
} ) ;
266
265
@@ -516,17 +515,18 @@ describe('EffectSources', () => {
516
515
const sources$ = of (
517
516
new class {
518
517
b$ = createEffect ( ( ) =>
519
- hot ( 'a--b--c --d' ) . pipe (
518
+ hot ( 'a--e-- b--e--c--e --d' ) . pipe (
520
519
map ( v => {
521
- if ( v == 'b ' ) throw new Error ( 'An Error' ) ;
520
+ if ( v == 'e ' ) throw new Error ( 'An Error' ) ;
522
521
return v ;
523
522
} )
524
523
)
525
524
) ;
526
525
} ( )
527
526
) ;
528
- // 👇 'b' is ignored.
529
- const expected = cold ( 'a-----c--d' ) ;
527
+
528
+ // 👇 'e' is ignored.
529
+ const expected = cold ( 'a-----b-----c-----d' ) ;
530
530
531
531
expect ( toActions ( sources$ ) ) . toBeObservable ( expected ) ;
532
532
} ) ;
Original file line number Diff line number Diff line change @@ -25,13 +25,7 @@ export function mergeEffects(
25
25
: sourceInstance [ propertyName ] ;
26
26
27
27
const resubscribable$ = resubscribeOnError
28
- ? observable$ . pipe (
29
- catchError ( error => {
30
- if ( errorHandler ) errorHandler . handleError ( error ) ;
31
- // Return observable that produces this particular effect
32
- return observable$ ;
33
- } )
34
- )
28
+ ? resubscribeInCaseOfError ( observable$ , errorHandler )
35
29
: observable$ ;
36
30
37
31
if ( dispatch === false ) {
@@ -56,3 +50,16 @@ export function mergeEffects(
56
50
57
51
return merge ( ...observables$ ) ;
58
52
}
53
+
54
+ function resubscribeInCaseOfError < T extends Action > (
55
+ observable$ : Observable < T > ,
56
+ errorHandler ?: ErrorHandler
57
+ ) : Observable < T > {
58
+ return observable$ . pipe (
59
+ catchError ( error => {
60
+ if ( errorHandler ) errorHandler . handleError ( error ) ;
61
+ // Return observable that produces this particular effect
62
+ return resubscribeInCaseOfError ( observable$ , errorHandler ) ;
63
+ } )
64
+ ) ;
65
+ }
You can’t perform that action at this time.
0 commit comments