function undoable(reducer) {
var rawConfig = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
__DEBUG__ = rawConfig.debug;
var config = {
initialState: rawConfig.initialState,
initTypes: parseActions(rawConfig.initTypes, ['@@redux/INIT', '@@INIT']),
limit: rawConfig.limit,
filter: rawConfig.filter || function () {
return true;
},
undoType: rawConfig.undoType || ActionTypes.UNDO,
redoType: rawConfig.redoType || ActionTypes.REDO,
jumpToPastType: rawConfig.jumpToPastType || ActionTypes.JUMP_TO_PAST,
jumpToFutureType: rawConfig.jumpToFutureType || ActionTypes.JUMP_TO_FUTURE
};
config.history = rawConfig.initialHistory || createHistory(config.initialState);
if (config.initTypes.length === 0) {
console.warn('redux-undo: supply at least one action type in initTypes to ensure initial state');
}
return function (state, action) {
debugStart(action, state);
var res = undefined;
switch (action.type) {
case config.undoType:
res = undo(state);
debug('after undo', res);
debugEnd();
return res ? updateState(state, res) : state;
case config.redoType:
res = redo(state);
debug('after redo', res);
debugEnd();
return res ? updateState(state, res) : state;
case config.jumpToPastType:
res = jumpToPast(state, action.index);
debug('after jumpToPast', res);
debugEnd();
return res ? updateState(state, res) : state;
case config.jumpToFutureType:
res = jumpToFuture(state, action.index);
debug('after jumpToFuture', res);
debugEnd();
return res ? updateState(state, res) : state;
default:
res = reducer(state && state.present, action);
if (config.initTypes.some(function (actionType) {
return actionType === action.type;
})) {
debug('reset history due to init action');
debugEnd();
return wrapState(_extends({}, state, createHistory(res)));
}
if (config.filter && typeof config.filter === 'function') {
if (!config.filter(action, res, state && state.present)) {
debug('filter prevented action, not storing it');
debugEnd();
return wrapState(_extends({}, state, {
present: res
}));
}
}
var history = state && state.present !== undefined ? state : config.history;
var updatedHistory = insert(history, res, config.limit);
debug('after insert', { history: updatedHistory, free: config.limit - length(updatedHistory) });
debugEnd();
return wrapState(_extends({}, state, updatedHistory));
}
};
}n/a
function distinctState() {
return function (action, currentState, previousState) {
return currentState !== previousState;
};
}n/a
function excludeAction() {
var rawActions = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var actions = parseActions(rawActions);
return function (action) {
return actions.indexOf(action.type) < 0;
};
}n/a
function ifAction(rawActions) {
console.error('Deprecation Warning: Please change `ifAction` to `includeAction`');
return includeAction(rawActions);
}n/a
function includeAction(rawActions) {
var actions = parseActions(rawActions);
return function (action) {
return actions.indexOf(action.type) >= 0;
};
}n/a
function parseActions(rawActions) {
var defaultValue = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
if (Array.isArray(rawActions)) {
return rawActions;
} else if (typeof rawActions === 'string') {
return [rawActions];
}
return defaultValue;
}n/a
function jumpToFuture(index) {
return { type: ActionTypes.JUMP_TO_FUTURE, index: index };
}...
perform undo/redo operations on your state:
```js
store.dispatch(ActionCreators.undo()) // undo the last action
store.dispatch(ActionCreators.redo()) // redo the last action
store.dispatch(ActionCreators.jumpToPast(index)) // jump to requested index in the past[] array
store.dispatch(ActionCreators.jumpToFuture(index)) // jump to requested index in the
future[] array
```
## Configuration
A configuration object can be passed to `undoable()` like this (values shown
are default values):
...function jumpToPast(index) {
return { type: ActionTypes.JUMP_TO_PAST, index: index };
}...
Then, you can use `store.dispatch()` and the undo/redo action creators to
perform undo/redo operations on your state:
```js
store.dispatch(ActionCreators.undo()) // undo the last action
store.dispatch(ActionCreators.redo()) // redo the last action
store.dispatch(ActionCreators.jumpToPast(index)) // jump to requested index in the past
[] array
store.dispatch(ActionCreators.jumpToFuture(index)) // jump to requested index in the future[] array
```
## Configuration
A configuration object can be passed to `undoable()` like this (values shown
...function redo() {
return { type: ActionTypes.REDO };
}...
```
Then, you can use `store.dispatch()` and the undo/redo action creators to
perform undo/redo operations on your state:
```js
store.dispatch(ActionCreators.undo()) // undo the last action
store.dispatch(ActionCreators.redo()) // redo the last action
store.dispatch(ActionCreators.jumpToPast(index)) // jump to requested index in the past[] array
store.dispatch(ActionCreators.jumpToFuture(index)) // jump to requested index in the future[] array
```
## Configuration
...function undo() {
return { type: ActionTypes.UNDO };
}...
import { ActionCreators } from 'redux-undo';
```
Then, you can use `store.dispatch()` and the undo/redo action creators to
perform undo/redo operations on your state:
```js
store.dispatch(ActionCreators.undo()) // undo the last action
store.dispatch(ActionCreators.redo()) // redo the last action
store.dispatch(ActionCreators.jumpToPast(index)) // jump to requested index in the past[] array
store.dispatch(ActionCreators.jumpToFuture(index)) // jump to requested index in the future[] array
```
...