Skip to content
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
4 changes: 3 additions & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export default function undoable (reducer, rawConfig = {}) {
? rawConfig.clearHistoryType
: [rawConfig.clearHistoryType || ActionTypes.CLEAR_HISTORY],
neverSkipReducer: rawConfig.neverSkipReducer || false,
ignoreInitialState: rawConfig.ignoreInitialState || false
ignoreInitialState: rawConfig.ignoreInitialState || false,
syncFilter: rawConfig.syncFilter || false
}

return (state = config.history, action = {}, ...slices) => {
Expand Down Expand Up @@ -270,6 +271,7 @@ export default function undoable (reducer, rawConfig = {}) {
const filteredState = {
...history,
present: res,
_latestUnfiltered: config.syncFilter ? res : history._latestUnfiltered,
group: null
}
debug.log('filter ignored action, not storing it in past')
Expand Down
16 changes: 16 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
expect(dummyState).to.deep.equal(incrementedState)
})

it('should synchronize latest unfiltered state to present when filtering actions', () => {
if (testConfig && testConfig.excludedActions) {
const excludedAction = { type: testConfig.excludedActions[0] }

const synchronizedFilteredReducer = undoable(countReducer, {
...undoableConfig,
syncFilter: true
})
let unsynchronized = mockUndoableReducer(mockInitialState, excludedAction)
let synchronized = synchronizedFilteredReducer(mockInitialState, excludedAction)
expect(unsynchronized.present).to.deep.equal(synchronized.present)
expect(unsynchronized._latestUnfiltered).to.not.deep.equal(synchronized._latestUnfiltered)
expect(synchronized.present).to.deep.equal(synchronized._latestUnfiltered)
}
})

it('should not record undefined actions', () => {
let dummyState = mockUndoableReducer(incrementedState, undefined)
expect(dummyState).to.deep.equal(incrementedState)
Expand Down
3 changes: 3 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ declare module 'redux-undo' {

/** Set to `true` to prevent the user from undoing to the initial state **/
ignoreInitialState?: boolean;

/** Set to `true` to synchronize the _latestUnfiltered state with present wen a excluded action is dispatched **/
syncFilter?: boolean;
}

interface Undoable {
Expand Down