Skip to content

Commit

Permalink
feat(store-devtools): use different action when recomputing state his…
Browse files Browse the repository at this point in the history
…tory (#1353)

Closes #1255
  • Loading branch information
tja4472 authored and brandonroberts committed Oct 16, 2018
1 parent 41a0d45 commit 1448a0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions modules/store-devtools/spec/store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -126,6 +127,20 @@ function createStore<T>(
}

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<number>;
let store: Store<number>;
Expand Down
5 changes: 4 additions & 1 deletion modules/store-devtools/src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1448a0e

Please sign in to comment.