Skip to content

Return last non-undefined state from getState() #106 #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/devTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function unliftState(liftedState) {
* Unlifts the DevTools store to act like the app's store.
*/
function unliftStore(liftedStore, reducer) {
let lastDefinedState;
return {
...liftedStore,
devToolsStore: liftedStore,
Expand All @@ -211,7 +212,11 @@ function unliftStore(liftedStore, reducer) {
return action;
},
getState() {
return unliftState(liftedStore.getState());
const state = unliftState(liftedStore.getState());
if (state !== undefined) {
lastDefinedState = state;
}
return lastDefinedState;
},
getReducer() {
return reducer;
Expand Down
16 changes: 16 additions & 0 deletions test/devTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ describe('devTools', () => {
expect(spy.calls[0].arguments[0]).toMatch(
/ReferenceError/
);

spy.restore();
});

it('returns the last non-undefined state from getState', () => {
let spy = spyOn(console, 'error');

store.dispatch({ type: 'INCREMENT' });
store.dispatch({ type: 'DECREMENT' });
store.dispatch({ type: 'INCREMENT' });
store.dispatch({ type: 'INCREMENT' });
expect(store.getState()).toBe(2);

store.replaceReducer(counterWithBug);
expect(store.getState()).toBe(1);

spy.restore();
});
});