-
Notifications
You must be signed in to change notification settings - Fork 410
/
Copy pathMapHistory.js
27 lines (25 loc) · 1.21 KB
/
MapHistory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const Undoable = require('redux-undo');
const assign = require('object-assign');
const mapConfigHistory = (reducer) => {
return (state, action) => {
let newState = reducer(state, action);
let unredoState;
// If undo modified the state we change mapStateSource
if (action.type === Undoable.ActionTypes.UNDO && state.past.length > 0) {
let mapC = assign({}, newState.present, {mapStateSource: "undoredo", style: state.present.style, resize: state.present.resize});
unredoState = assign({}, newState, {present: mapC});
} else if (action.type === Undoable.ActionTypes.REDO && state.future.length > 0) {
let mapC = assign({}, newState.present, {mapStateSource: "undoredo", style: state.present.style, resize: state.present.resize});
unredoState = assign({}, newState, {present: mapC});
}
return unredoState || {past: newState.past, present: newState.present, future: newState.future};
};
};
module.exports = mapConfigHistory;