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
3,163 changes: 1,914 additions & 1,249 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --mode=production",
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --mode=production",
"clean": "./node_modules/.bin/rimraf lib dist es",
"lint": "./node_modules/.bin/eslint webpack.config.babel.js src test",
"prepublish": "npm run lint && npm run test && npm run clean && npm run build",
"test": "cross-env NODE_ENV=test ./node_modules/.bin/mocha --require @babel/register",
"clean": "npx rimraf lib/ dist/ es/",
"lint": "npx eslint webpack.config.babel.js src test",
"prepublish": "npm-run-all --sequential lint test clean build",
"test": "cross-env NODE_ENV=test npx mocha --require @babel/register",
"test:bail": "npm run test:watch -- --bail",
"test:cov": "./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover --root src/ ./node_modules/.bin/_mocha",
"test:cov": "npx babel-node ./node_modules/.bin/isparta cover --root src/ ./node_modules/.bin/_mocha",
"test:coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test:watch": "npm run test -- --watch"
},
Expand All @@ -55,31 +55,31 @@
},
"homepage": "https://github.com/omnidan/redux-undo",
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@babel/node": "^7.2.2",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/register": "^7.4.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/preset-env": "^7.7.6",
"@babel/register": "^7.7.4",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"cross-env": "^5.2.0",
"eslint": "^5.15.3",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"expect": "^24.5.0",
"coveralls": "^3.0.9",
"cross-env": "^6.0.3",
"eslint": "^6.7.2",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"expect": "^24.9.0",
"isparta": "^4.1.1",
"mocha": "^6.0.2",
"mocha": "^6.2.2",
"mocha-lcov-reporter": "^1.3.0",
"npm-run-all": "^4.1.5",
"redux": "^4.0.1",
"rimraf": "^2.6.3",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
"redux": "^4.0.4",
"rimraf": "^3.0.0",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10"
}
}
2 changes: 1 addition & 1 deletion src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function initBuffer () {

/* istanbul ignore next: debug messaging is not tested */
function printBuffer () {
let { header, prev, next, action, msgs } = displayBuffer
const { header, prev, next, action, msgs } = displayBuffer
if (console.group) {
console.groupCollapsed(...header)
console.log(...prev)
Expand Down
12 changes: 8 additions & 4 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function createHistory (state, ignoreInitialState) {
// ignoreInitialState essentially prevents the user from undoing to the
// beginning, in the case that the undoable reducer handles initialization
// in a way that can't be redone simply
let history = newHistory([], state, [])
const history = newHistory([], state, [])
if (ignoreInitialState) {
history._latestUnfiltered = null
}
Expand Down Expand Up @@ -109,15 +109,17 @@ export default function undoable (reducer, rawConfig = {}) {
debug.log('history is uninitialized')

if (state === undefined) {
const clearHistoryAction = { type: ActionTypes.CLEAR_HISTORY }
const start = reducer(state, clearHistoryAction, ...slices)
const createHistoryAction = { type: '@@redux-undo/CREATE_HISTORY' }
const start = reducer(state, createHistoryAction, ...slices)

history = createHistory(
start,
config.ignoreInitialState
)

debug.log('do not set initialState on probe actions')
debug.end(history)
return history
} else if (isHistory(state)) {
history = initialState = config.ignoreInitialState
? state : newHistory(
Expand Down Expand Up @@ -207,6 +209,7 @@ export default function undoable (reducer, rawConfig = {}) {
return history
}

/* eslint-disable-next-line no-case-declarations */
const filtered = typeof config.filter === 'function' && !config.filter(
action,
res,
Expand All @@ -215,7 +218,7 @@ export default function undoable (reducer, rawConfig = {}) {

if (filtered) {
// if filtering an action, merely update the present
let filteredState = newHistory(
const filteredState = newHistory(
history.past,
res,
history.future,
Expand All @@ -229,6 +232,7 @@ export default function undoable (reducer, rawConfig = {}) {
return filteredState
}

/* eslint-disable-next-line no-case-declarations */
const group = config.groupBy(action, res, history)
if (group != null && group === history.group) {
// if grouping with the previous action, only update the present
Expand Down
2 changes: 1 addition & 1 deletion test/combineFilters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function runTestCombineFilters () {
})

it('should not call remaining filters if one already returned false', () => {
let act = { hasBeenCalled: false }
const act = { hasBeenCalled: false }
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled)

combined(act, 2)
Expand Down
26 changes: 13 additions & 13 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runTests('Initial State equals 100', {
})
runTests('Initial State that looks like a history', {
undoableConfig: {},
initialStoreState: { 'present': 0 },
initialStoreState: { present: 0 },
testConfig: {
checkSlices: true
}
Expand Down Expand Up @@ -275,7 +275,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should not record non state changing actions', () => {
let dummyState = mockUndoableReducer(incrementedState, { type: 'DUMMY' })
const dummyState = mockUndoableReducer(incrementedState, { type: 'DUMMY' })
expect(dummyState).to.deep.equal(incrementedState)
})

Expand All @@ -287,24 +287,24 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
...undoableConfig,
syncFilter: true
})
let unsynchronized = mockUndoableReducer(mockInitialState, excludedAction)
let synchronized = synchronizedFilteredReducer(mockInitialState, excludedAction)
const unsynchronized = mockUndoableReducer(mockInitialState, excludedAction)
const 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)
const dummyState = mockUndoableReducer(incrementedState, undefined)
expect(dummyState).to.deep.equal(incrementedState)
})

it('should reset upon init actions', () => {
let reInitializedState
if (undoableConfig && undoableConfig.initTypes) {
if (undoableConfig.initTypes.length > 0) {
let initType = Array.isArray(undoableConfig.initTypes) ? undoableConfig.initTypes[0] : undoableConfig.initTypes
const initType = Array.isArray(undoableConfig.initTypes) ? undoableConfig.initTypes[0] : undoableConfig.initTypes
reInitializedState = mockUndoableReducer(incrementedState, { type: initType })
expect(reInitializedState).to.deep.equal(mockInitialState)
} else {
Expand All @@ -319,7 +319,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should increment when action is dispatched to store', () => {
let expectedResult = store.getState().present + 1
const expectedResult = store.getState().present + 1
store.dispatch({ type: 'INCREMENT' })
expect(store.getState().present).to.equal(expectedResult)
})
Expand Down Expand Up @@ -457,7 +457,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should do nothing if \'past\' is empty', () => {
let undoInitialState = mockUndoableReducer(mockInitialState, ActionCreators.undo())
const undoInitialState = mockUndoableReducer(mockInitialState, ActionCreators.undo())
if (!mockInitialState.past.length) {
expect(undoInitialState.present).to.deep.equal(mockInitialState.present)
}
Expand Down Expand Up @@ -527,7 +527,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should do nothing if \'future\' is empty', () => {
let secondRedoState = mockUndoableReducer(redoState, ActionCreators.redo())
const secondRedoState = mockUndoableReducer(redoState, ActionCreators.redo())
if (!redoState.future.length) {
expect(secondRedoState.present).to.deep.equal(redoState.present)
}
Expand Down Expand Up @@ -563,7 +563,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should do nothing if past index is out of bounds', () => {
let jumpToOutOfBounds = mockUndoableReducer(incrementedState, ActionCreators.jumpToPast(-1))
const jumpToOutOfBounds = mockUndoableReducer(incrementedState, ActionCreators.jumpToPast(-1))
expect(jumpToOutOfBounds).to.deep.equal(incrementedState)
})

Expand Down Expand Up @@ -599,7 +599,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should do nothing if future index is out of bounds', () => {
let jumpToOutOfBounds = mockUndoableReducer(mockInitialState, ActionCreators.jumpToFuture(-1))
const jumpToOutOfBounds = mockUndoableReducer(mockInitialState, ActionCreators.jumpToFuture(-1))
expect(jumpToOutOfBounds).to.deep.equal(mockInitialState)
})

Expand Down Expand Up @@ -632,7 +632,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
let doubleUndoState
let doubleRedoState
before('perform a jump action', () => {
let doubleIncrementedState = mockUndoableReducer(incrementedState, { type: 'INCREMENT' })
const doubleIncrementedState = mockUndoableReducer(incrementedState, { type: 'INCREMENT' })
jumpToPastState = mockUndoableReducer(doubleIncrementedState, ActionCreators.jump(jumpStepsToPast))
jumpToFutureState = mockUndoableReducer(mockInitialState, ActionCreators.jump(jumpStepsToFuture))
doubleUndoState = mockUndoableReducer(doubleIncrementedState, ActionCreators.undo())
Expand All @@ -654,7 +654,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
})

it('should do nothing if steps is 0', () => {
let jumpToCurrentState = mockUndoableReducer(mockInitialState, ActionCreators.jump(0))
const jumpToCurrentState = mockUndoableReducer(mockInitialState, ActionCreators.jump(0))
expect(jumpToCurrentState).to.deep.equal(mockInitialState)
})

Expand Down
12 changes: 6 additions & 6 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ declare module 'redux-undo' {
past: State[];
present: State;
future: State[];
_latestUnfiltered: State;
group: any;
index: number;
limit: number;
_latestUnfiltered?: State;
group?: any;
index?: number;
limit?: number;
}

export type FilterFunction = <State>(action: Action, currentState: State, previousHistory: StateWithHistory<State>) => boolean;
export type GroupByFunction = <State>(action: Action, currentState: State, previousHistory: StateWithHistory<State>) => any;
export type GroupByFunction = (action: Action) => any;
export type CombineFilters = (...filters: FilterFunction[]) => FilterFunction;

export class ActionCreators {
Expand Down Expand Up @@ -57,7 +57,7 @@ declare module 'redux-undo' {
jumpToFutureType?: string;

/** Define custom action type for this clearHistory action */
clearHistoryType?: string;
clearHistoryType?: string | string[];

/** History will be (re)set upon init action type */
initTypes?: string[];
Expand Down