Skip to content

Instantly share code, notes, and snippets.

@ktsn
Last active October 14, 2016 15:07
Show Gist options
  • Save ktsn/ee01838ad116fd8b4c952e2588471880 to your computer and use it in GitHub Desktop.
Save ktsn/ee01838ad116fd8b4c952e2588471880 to your computer and use it in GitHub Desktop.
export const ({ shouldRecord, invertAction, isUndo, isRedo }) => {
const history = []
return store => next => action => {
if (isUndo(action)) {
const invert = invertAction(lastUndoable(history))
history.push(invert)
next(invert)
return
}
if (isRedo(action)) {
const invert = invertAction(lastRedoable(history))
history.push(invert)
next(invert)
return
}
if (shouldRecord(action)) {
history.push(action)
}
next(action)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment