1
1
import difference from 'lodash/difference' ;
2
+ import union from 'lodash/union' ;
2
3
3
4
export const ActionTypes = {
4
5
PERFORM_ACTION : 'PERFORM_ACTION' ,
@@ -7,6 +8,7 @@ export const ActionTypes = {
7
8
COMMIT : 'COMMIT' ,
8
9
SWEEP : 'SWEEP' ,
9
10
TOGGLE_ACTION : 'TOGGLE_ACTION' ,
11
+ SET_ACTIONS_ACTIVE : 'SET_ACTIONS_ACTIVE' ,
10
12
JUMP_TO_STATE : 'JUMP_TO_STATE' ,
11
13
IMPORT_STATE : 'IMPORT_STATE'
12
14
} ;
@@ -45,6 +47,10 @@ export const ActionCreators = {
45
47
return { type : ActionTypes . TOGGLE_ACTION , id } ;
46
48
} ,
47
49
50
+ setActionsActive ( start , end , active = true ) {
51
+ return { type : ActionTypes . SET_ACTIONS_ACTIVE , start, end, active } ;
52
+ } ,
53
+
48
54
jumpToState ( index ) {
49
55
return { type : ActionTypes . JUMP_TO_STATE , index } ;
50
56
} ,
@@ -244,6 +250,22 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer, options
244
250
minInvalidatedStateIndex = stagedActionIds . indexOf ( actionId ) ;
245
251
break ;
246
252
}
253
+ case ActionTypes . SET_ACTIONS_ACTIVE : {
254
+ // Toggle whether an action with given ID is skipped.
255
+ // Being skipped means it is a no-op during the computation.
256
+ const { start, end, active } = liftedAction ;
257
+ const actionIds = [ ] ;
258
+ for ( let i = start ; i < end ; i ++ ) actionIds . push ( i ) ;
259
+ if ( active ) {
260
+ skippedActionIds = difference ( skippedActionIds , actionIds ) ;
261
+ } else {
262
+ skippedActionIds = union ( skippedActionIds , actionIds ) ;
263
+ }
264
+
265
+ // Optimization: we know history before this action hasn't changed
266
+ minInvalidatedStateIndex = stagedActionIds . indexOf ( start ) ;
267
+ break ;
268
+ }
247
269
case ActionTypes . JUMP_TO_STATE : {
248
270
// Without recomputing anything, move the pointer that tell us
249
271
// which state is considered the current one. Useful for sliders.
0 commit comments