From 9345fc6f775154e597b77d1339e962c79cd5b41a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 8 Jun 2017 16:42:57 -0400 Subject: [PATCH] Test history when deciding to return same state --- editor/utils/test/undoable-reducer.js | 14 +++++++++++--- editor/utils/undoable-reducer.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/editor/utils/test/undoable-reducer.js b/editor/utils/test/undoable-reducer.js index 44d5e75299877a..1c7a020651d0a2 100644 --- a/editor/utils/test/undoable-reducer.js +++ b/editor/utils/test/undoable-reducer.js @@ -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' ); @@ -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 ); + } ); } ); } ); diff --git a/editor/utils/undoable-reducer.js b/editor/utils/undoable-reducer.js index d254bcea3721f4..95415ff02828ce 100644 --- a/editor/utils/undoable-reducer.js +++ b/editor/utils/undoable-reducer.js @@ -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; }