Skip to content

Commit

Permalink
Merge pull request #1084 from WordPress/fix/state-reference-change
Browse files Browse the repository at this point in the history
Prevent unhandled action from returning new state reference
  • Loading branch information
aduth authored Jul 24, 2017
2 parents e82a407 + 9345fc6 commit 941fe34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions editor/utils/test/undoable-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ describe( 'undoableReducer', () => {
} );

describe( 'combineUndoableReducers()', () => {
const reducer = combineUndoableReducers( {
count: ( state = 0 ) => state,
} );

it( 'should return a combined reducer with getters', () => {
const reducer = combineUndoableReducers( {
count: ( state = 0 ) => state,
} );
const state = reducer( undefined, {} );

expect( typeof reducer ).toBe( 'function' );
Expand All @@ -100,5 +101,12 @@ describe( 'undoableReducer', () => {
future: [],
} );
} );

it( 'should return same reference if state has not changed', () => {
const original = reducer( undefined, {} );
const state = reducer( original, {} );

expect( state ).toBe( original );
} );
} );
} );
2 changes: 1 addition & 1 deletion editor/utils/undoable-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function combineUndoableReducers( reducers, options ) {

return ( state = initialState, action ) => {
const nextState = reducer( state.history, action );
if ( nextState === state.history.present ) {
if ( nextState === state.history ) {
return state;
}

Expand Down

0 comments on commit 941fe34

Please sign in to comment.