Settings

Theme

Show HN: Redux-undo – Simple undo/redo functionality for Redux state containers

github.com

41 points by omnidan 10 years ago · 4 comments

Reader

europestup 10 years ago

What about undoing on the server though? Doing that on the client only isn't very good useful in most situations I can think of.

  • omnidanOP 10 years ago

    That's an interesting question. The simplest way would be listening to state changes in the store and then syncing the state with the server. Since undos/redos are normal redux actions, you can just handle them like any other action in redux.

    For example, in an application I wrote, I do `store.subscribe(autoSaveFunction)` which will automatically save all changes to the state. Of course, you can also only store parts of the state, etc, but this is more redux related than redux-undo related.

nik-graf 10 years ago

Does it also work with immutable data-structures?

  • omnidanOP 10 years ago

    I haven't tested it yet, but it should. The magic behind redux-undo is a reducer enhancer (higher order reducer) - it returns a function that processes undo/redo and then (if appropriate) calls your reducer. If your reducer uses immutable data-structures, redux-undo will simply store your data (immutable or not) in the history.

    redux-undo itself doesn't use immutable data structures, though (for dependency reasons). However, I do make sure not to change any data directly. (you know, the usual redux reducer guidelines)

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection