diff --git a/modules/store-devtools/spec/store.spec.ts b/modules/store-devtools/spec/store.spec.ts index f7a5f010b3..57271373a7 100644 --- a/modules/store-devtools/spec/store.spec.ts +++ b/modules/store-devtools/spec/store.spec.ts @@ -259,6 +259,16 @@ describe('Store Devtools', () => { expect(getState()).toBe(2); }); + it('should jump to action', () => { + store.dispatch({ type: 'INCREMENT' }); + store.dispatch({ type: 'DECREMENT' }); + store.dispatch({ type: 'INCREMENT' }); + expect(getState()).toBe(1); + + devtools.jumpToAction(2); + expect(getState()).toBe(0); + }); + it('should replace the reducer and preserve previous states', () => { store.dispatch({ type: 'INCREMENT' }); store.dispatch({ type: 'DECREMENT' }); diff --git a/modules/store-devtools/src/actions.ts b/modules/store-devtools/src/actions.ts index 8ff1800d48..ce0cd1aaa9 100644 --- a/modules/store-devtools/src/actions.ts +++ b/modules/store-devtools/src/actions.ts @@ -8,6 +8,7 @@ export const SWEEP = 'SWEEP'; export const TOGGLE_ACTION = 'TOGGLE_ACTION'; export const SET_ACTIONS_ACTIVE = 'SET_ACTIONS_ACTIVE'; export const JUMP_TO_STATE = 'JUMP_TO_STATE'; +export const JUMP_TO_ACTION = 'JUMP_TO_ACTION'; export const IMPORT_STATE = 'IMPORT_STATE'; export class PerformAction implements Action { @@ -67,6 +68,12 @@ export class JumpToState implements Action { constructor(public index: number) {} } +export class JumpToAction implements Action { + readonly type = JUMP_TO_ACTION; + + constructor(public actionId: number) {} +} + export class ImportState implements Action { readonly type = IMPORT_STATE; @@ -82,4 +89,5 @@ export type All = | ToggleAction | SetActionsActive | JumpToState + | JumpToAction | ImportState; diff --git a/modules/store-devtools/src/devtools.ts b/modules/store-devtools/src/devtools.ts index caa66aa8c0..b964f35fda 100644 --- a/modules/store-devtools/src/devtools.ts +++ b/modules/store-devtools/src/devtools.ts @@ -133,6 +133,10 @@ export class StoreDevtools implements Observer { this.dispatch(new Actions.ToggleAction(id)); } + jumpToAction(actionId: number) { + this.dispatch(new Actions.JumpToAction(actionId)); + } + jumpToState(index: number) { this.dispatch(new Actions.JumpToState(index)); } diff --git a/modules/store-devtools/src/reducer.ts b/modules/store-devtools/src/reducer.ts index e7fa19af75..9319bc5be5 100644 --- a/modules/store-devtools/src/reducer.ts +++ b/modules/store-devtools/src/reducer.ts @@ -259,6 +259,14 @@ export function liftReducerWith( minInvalidatedStateIndex = Infinity; break; } + case Actions.JUMP_TO_ACTION: { + // Jumps to a corresponding state to a specific action. + // Useful when filtering actions. + const index = stagedActionIds.indexOf(liftedAction.actionId); + if (index !== -1) currentStateIndex = index; + minInvalidatedStateIndex = Infinity; + break; + } case Actions.SWEEP: { // Forget any actions that are currently being skipped. stagedActionIds = difference(stagedActionIds, skippedActionIds);