File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,16 @@ describe('Store Devtools', () => {
259
259
expect ( getState ( ) ) . toBe ( 2 ) ;
260
260
} ) ;
261
261
262
+ it ( 'should jump to action' , ( ) => {
263
+ store . dispatch ( { type : 'INCREMENT' } ) ;
264
+ store . dispatch ( { type : 'DECREMENT' } ) ;
265
+ store . dispatch ( { type : 'INCREMENT' } ) ;
266
+ expect ( getState ( ) ) . toBe ( 1 ) ;
267
+
268
+ devtools . jumpToAction ( 2 ) ;
269
+ expect ( getState ( ) ) . toBe ( 0 ) ;
270
+ } ) ;
271
+
262
272
it ( 'should replace the reducer and preserve previous states' , ( ) => {
263
273
store . dispatch ( { type : 'INCREMENT' } ) ;
264
274
store . dispatch ( { type : 'DECREMENT' } ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export const SWEEP = 'SWEEP';
8
8
export const TOGGLE_ACTION = 'TOGGLE_ACTION' ;
9
9
export const SET_ACTIONS_ACTIVE = 'SET_ACTIONS_ACTIVE' ;
10
10
export const JUMP_TO_STATE = 'JUMP_TO_STATE' ;
11
+ export const JUMP_TO_ACTION = 'JUMP_TO_ACTION' ;
11
12
export const IMPORT_STATE = 'IMPORT_STATE' ;
12
13
13
14
export class PerformAction implements Action {
@@ -67,6 +68,12 @@ export class JumpToState implements Action {
67
68
constructor ( public index : number ) { }
68
69
}
69
70
71
+ export class JumpToAction implements Action {
72
+ readonly type = JUMP_TO_ACTION ;
73
+
74
+ constructor ( public actionId : number ) { }
75
+ }
76
+
70
77
export class ImportState implements Action {
71
78
readonly type = IMPORT_STATE ;
72
79
@@ -82,4 +89,5 @@ export type All =
82
89
| ToggleAction
83
90
| SetActionsActive
84
91
| JumpToState
92
+ | JumpToAction
85
93
| ImportState ;
Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ export class StoreDevtools implements Observer<any> {
133
133
this . dispatch ( new Actions . ToggleAction ( id ) ) ;
134
134
}
135
135
136
+ jumpToAction ( actionId : number ) {
137
+ this . dispatch ( new Actions . JumpToAction ( actionId ) ) ;
138
+ }
139
+
136
140
jumpToState ( index : number ) {
137
141
this . dispatch ( new Actions . JumpToState ( index ) ) ;
138
142
}
Original file line number Diff line number Diff line change @@ -259,6 +259,14 @@ export function liftReducerWith(
259
259
minInvalidatedStateIndex = Infinity ;
260
260
break ;
261
261
}
262
+ case Actions . JUMP_TO_ACTION : {
263
+ // Jumps to a corresponding state to a specific action.
264
+ // Useful when filtering actions.
265
+ const index = stagedActionIds . indexOf ( liftedAction . actionId ) ;
266
+ if ( index !== - 1 ) currentStateIndex = index ;
267
+ minInvalidatedStateIndex = Infinity ;
268
+ break ;
269
+ }
262
270
case Actions . SWEEP : {
263
271
// Forget any actions that are currently being skipped.
264
272
stagedActionIds = difference ( stagedActionIds , skippedActionIds ) ;
You can’t perform that action at this time.
0 commit comments