Last active
October 14, 2016 15:07
-
-
Save ktsn/ee01838ad116fd8b4c952e2588471880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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