1
1
import { Action , Epic } from '@sigi/types'
2
2
import produce , { Draft } from 'immer'
3
3
import { Observable , merge } from 'rxjs'
4
- import { map , filter , skip , ignoreElements } from 'rxjs/operators'
4
+ import { map , filter , ignoreElements } from 'rxjs/operators'
5
5
6
6
import { hmrEnabled , hmrInstanceCache } from './hmr'
7
7
import { getDecoratedActions , getActionsToSkip } from './metadata'
@@ -43,6 +43,8 @@ export abstract class EffectModule<S> {
43
43
private readonly actionStreams : any = { }
44
44
private readonly retryActionsCreator : any = { }
45
45
private readonly actionNames : string [ ] = [ ]
46
+ private actionsToRetry : Set < string > = new Set ( )
47
+ private actionsToSkip ! : string [ ]
46
48
private restoredFromSSR = false
47
49
48
50
get state$ ( ) {
@@ -116,13 +118,23 @@ export abstract class EffectModule<S> {
116
118
context . internalDefaultState = value
117
119
if ( ! context . store . ready ) {
118
120
context . store . setup ( context . getDefaultState ( ) )
121
+ context . actionsToRetry = new Set ( _globalThis [ RETRY_KEY_SYMBOL ] ?. [ this . moduleName ] || [ ] )
122
+ context . actionsToSkip = context . restoredFromSSR
123
+ ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
124
+ getActionsToSkip ( context . constructor . prototype ) || [ ]
125
+ : [ ]
119
126
}
120
127
return rawSetter . call ( this , value )
121
128
}
122
129
} else if ( 'value' in attr ) {
123
130
context . internalDefaultState = attr . value
124
131
if ( ! context . store . ready ) {
125
132
context . store . setup ( context . getDefaultState ( ) )
133
+ context . actionsToRetry = new Set ( _globalThis [ RETRY_KEY_SYMBOL ] ?. [ context . moduleName ] || [ ] )
134
+ context . actionsToSkip = context . restoredFromSSR
135
+ ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
136
+ getActionsToSkip ( context . constructor . prototype ) || [ ]
137
+ : [ ]
126
138
}
127
139
}
128
140
}
@@ -133,6 +145,11 @@ export abstract class EffectModule<S> {
133
145
context . internalDefaultState = value
134
146
if ( ! context . store . ready ) {
135
147
context . store . setup ( context . getDefaultState ( ) )
148
+ context . actionsToRetry = new Set ( _globalThis [ RETRY_KEY_SYMBOL ] ?. [ context . moduleName ] || [ ] )
149
+ context . actionsToSkip = context . restoredFromSSR
150
+ ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
151
+ getActionsToSkip ( context . constructor . prototype ) || [ ]
152
+ : [ ]
136
153
}
137
154
}
138
155
return Reflect . set ( target , p , value , receiver )
@@ -144,6 +161,9 @@ export abstract class EffectModule<S> {
144
161
this . internalDefaultState = value
145
162
if ( ! this . store . ready ) {
146
163
this . store . setup ( this . getDefaultState ( ) )
164
+ this . actionsToRetry = new Set ( _globalThis [ RETRY_KEY_SYMBOL ] ?. [ this . moduleName ] || [ ] )
165
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
166
+ this . actionsToSkip = this . restoredFromSSR ? getActionsToSkip ( this . constructor . prototype ) || [ ] : [ ]
147
167
}
148
168
} ,
149
169
get : ( ) => {
@@ -254,16 +274,16 @@ export abstract class EffectModule<S> {
254
274
}
255
275
256
276
this . actionNames . push ( ...effectKeys )
257
- const actionsToRetry = new Set ( _globalThis [ RETRY_KEY_SYMBOL ] ?. [ this . moduleName ] || [ ] )
258
- const actionsToSkip = this . restoredFromSSR ? getActionsToSkip ( this . constructor . prototype ) : undefined
259
277
260
278
return ( action$ : Observable < Action > ) => {
261
279
return merge (
262
280
...effectKeys . map ( ( name ) => {
263
281
const effect : Effect < unknown > = ( this as any ) [ name ]
264
282
const payload$ = action$ . pipe (
265
- filter ( ( { type } ) => type === name ) ,
266
- skip ( ! actionsToRetry . has ( name ) && actionsToSkip ?. includes ( name ) ? 1 : 0 ) ,
283
+ filter ( ( { type } , index ) => {
284
+ const skipCount = ! this . actionsToRetry . has ( name ) && this . actionsToSkip ?. includes ( name ) ? 1 : 0
285
+ return type === name && skipCount <= index
286
+ } ) ,
267
287
map ( ( { payload } ) => payload ) ,
268
288
)
269
289
this . retryActionsCreator [ name ] = ( ) =>
0 commit comments