From 1448a0ee4fc18306f5b4d84279f707e49672fe51 Mon Sep 17 00:00:00 2001 From: tja4472 Date: Tue, 16 Oct 2018 03:16:08 +0100 Subject: [PATCH] feat(store-devtools): use different action when recomputing state history (#1353) Closes #1255 --- modules/store-devtools/spec/store.spec.ts | 15 +++++++++++++++ modules/store-devtools/src/reducer.ts | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/store-devtools/spec/store.spec.ts b/modules/store-devtools/spec/store.spec.ts index 1e005c0609..de5ef3432c 100644 --- a/modules/store-devtools/spec/store.spec.ts +++ b/modules/store-devtools/spec/store.spec.ts @@ -17,6 +17,7 @@ import { } from '../'; import { IS_EXTENSION_OR_MONITOR_PRESENT } from '../src/instrument'; import { PerformAction } from '../src/actions'; +import { RECOMPUTE_STATE } from '../src/reducer'; const counter = jasmine .createSpy('counter') @@ -126,6 +127,20 @@ function createStore( } describe('Store Devtools', () => { + describe('reducer', () => { + it('should call @ngrx/devtools/recompute-state action', () => { + const fixture = createStore(doubleCounter); + counter.calls.reset(); + fixture.replaceReducer(counter); + + const allArgs = counter.calls.allArgs(); + expect(allArgs.length).toEqual(3); + expect(allArgs[0][1].type).toEqual(UPDATE); + expect(allArgs[1][1].type).toEqual(RECOMPUTE_STATE); + expect(allArgs[2][1].type).toEqual(RECOMPUTE_STATE); + }); + }); + describe('Instrumentation', () => { let fixture: Fixture; let store: Store; diff --git a/modules/store-devtools/src/reducer.ts b/modules/store-devtools/src/reducer.ts index 97dc22a67e..547a1dc015 100644 --- a/modules/store-devtools/src/reducer.ts +++ b/modules/store-devtools/src/reducer.ts @@ -25,6 +25,9 @@ export type Actions = DevtoolsActions.All | CoreActions; export const INIT_ACTION = { type: INIT }; +export const RECOMPUTE_STATE = '@ngrx/devtools/recompute-state' as '@ngrx/devtools/recompute-state'; +export const RECOMPUTE_STATE_ACTION = { type: RECOMPUTE_STATE }; + export interface ComputedState { state: any; error: any; @@ -501,7 +504,7 @@ export function liftReducerWith( // Recompute state history with latest reducer and update action computedStates = computedStates.map(cmp => ({ ...cmp, - state: reducer(cmp.state, liftedAction), + state: reducer(cmp.state, RECOMPUTE_STATE_ACTION), })); currentStateIndex = stagedActionIds.length - 1;