9
9
import { difference , liftAction } from './utils' ;
10
10
import * as Actions from './actions' ;
11
11
import { StoreDevtoolsConfig } from './config' ;
12
+ import { PerformAction } from './actions' ;
12
13
13
14
export type InitAction = {
14
15
readonly type : typeof INIT ;
@@ -300,7 +301,6 @@ export function liftReducerWith(
300
301
} = liftedAction . nextLiftedState ) ;
301
302
break ;
302
303
}
303
- case UPDATE :
304
304
case INIT : {
305
305
// Always recompute states on hot reload and init.
306
306
minInvalidatedStateIndex = 0 ;
@@ -325,6 +325,66 @@ export function liftReducerWith(
325
325
326
326
break ;
327
327
}
328
+ case UPDATE : {
329
+ const stateHasErrors =
330
+ computedStates . filter ( state => state . error ) . length > 0 ;
331
+
332
+ if ( stateHasErrors ) {
333
+ // Recompute all states
334
+ minInvalidatedStateIndex = 0 ;
335
+
336
+ if ( options . maxAge && stagedActionIds . length > options . maxAge ) {
337
+ // States must be recomputed before committing excess.
338
+ computedStates = recomputeStates (
339
+ computedStates ,
340
+ minInvalidatedStateIndex ,
341
+ reducer ,
342
+ committedState ,
343
+ actionsById ,
344
+ stagedActionIds ,
345
+ skippedActionIds
346
+ ) ;
347
+
348
+ commitExcessActions ( stagedActionIds . length - options . maxAge ) ;
349
+
350
+ // Avoid double computation.
351
+ minInvalidatedStateIndex = Infinity ;
352
+ }
353
+ } else {
354
+ if ( currentStateIndex === stagedActionIds . length - 1 ) {
355
+ currentStateIndex ++ ;
356
+ }
357
+
358
+ // Add a new action to only recompute state
359
+ const actionId = nextActionId ++ ;
360
+ actionsById [ actionId ] = new PerformAction ( liftedAction ) ;
361
+ stagedActionIds = [ ...stagedActionIds , actionId ] ;
362
+
363
+ minInvalidatedStateIndex = stagedActionIds . length - 1 ;
364
+
365
+ // States must be recomputed before committing excess.
366
+ computedStates = recomputeStates (
367
+ computedStates ,
368
+ minInvalidatedStateIndex ,
369
+ reducer ,
370
+ committedState ,
371
+ actionsById ,
372
+ stagedActionIds ,
373
+ skippedActionIds
374
+ ) ;
375
+
376
+ currentStateIndex = minInvalidatedStateIndex ;
377
+
378
+ if ( options . maxAge && stagedActionIds . length > options . maxAge ) {
379
+ commitExcessActions ( stagedActionIds . length - options . maxAge ) ;
380
+ }
381
+
382
+ // Avoid double computation.
383
+ minInvalidatedStateIndex = Infinity ;
384
+ }
385
+
386
+ break ;
387
+ }
328
388
default : {
329
389
// If the action is not recognized, it's a monitor action.
330
390
// Optimization: a monitor action can't change history.
0 commit comments