Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo / redo using immer Patch ? #124

Closed
vikasaditya opened this issue Mar 18, 2019 · 7 comments
Closed

Undo / redo using immer Patch ? #124

vikasaditya opened this issue Mar 18, 2019 · 7 comments

Comments

@vikasaditya
Copy link

hi,

We are using you lib in a large project and team is loving your approach.

There is one thing that is not clear to me at least is how can we use immer Patch to implement an undo / redo ?

And if not then any pointers would be greatly appreciated, maybe something like redux undo/redo example?

Thanks

@ctrlplusb
Copy link
Owner

Hey @vikasaditya

Great to hear. 👍

I would try to avoid leaning on immer to provide you with this functionality. You could use the redux-undo library, and then use it's undoable within the reducerEnhancer configuration value of createStore.

Kind of like:

import undoable from 'redux-undo';
import { createStore } from 'easy-peasy';

const store = createStore(model, {
  reducerEnhancer: reducer => undoable(reducer, reduxUndoConfig),
});

It looks like redux-undo supports filtering etc, which you could use to limit the feature to specific paths of your state (e.g. action.startsWith('action.notifications')).

Hope this helps.

@vikasaditya
Copy link
Author

Thanks for prompt reply.
I will get your suggestion tested. Will update here for anyone else looking.
Then we can close this ticket. Also you should label this "question"

@vikasaditya
Copy link
Author

Can you take a quick look at https://codesandbox.io/s/rj5mnjz7wn ?
If we add redux-undo, it crashes in the thunk with state not defined. Any pointers?

@ctrlplusb
Copy link
Owner

My apologies @vikasaditya I looked into this a bit more and we won't be able to support redux-undo. This is because it changes the shape of your store state. :(

I will have a think and if any new ideas come to me I will let you know.

@vikasaditya
Copy link
Author

okey, will wait.
Expose immer api via store?

@ctrlplusb
Copy link
Owner

I did have some ideas, but I need to let them sit for a while. Generally it takes me a few cycles/revisions until I come up with an API/solution that is effective.

@ctrlplusb
Copy link
Owner

Not planning anything like this for now. Going to leave the problem in user-land for now unless much bigger demand comes for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants