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

Add support to group actions? #331

Open
mrcoles opened this issue Sep 18, 2023 · 2 comments
Open

Add support to group actions? #331

mrcoles opened this issue Sep 18, 2023 · 2 comments

Comments

@mrcoles
Copy link

mrcoles commented Sep 18, 2023

Hi, thanks for this repo! Feature request—it’d be really nice if I could group actions in the history, so one or more get grouped in a single undo action.

An example use-case would be when an element’s position is stored in state along with other attributes and I might want a sequence of position changes to group together while other attribute updates would be individual states in the history.

In the meantime, my workarounds are either trying to manage additional state in a separate context (which solves a lot of the scenarios, but eventually gets dodgy) or I could switch to redux and use redux-undo, which allows you set a custom grouping function.

@frontendphil
Copy link
Owner

Hey @mrcoles, thanks for the idea. I have to think about this some more :) Currently, react-undo-redo does not make any assumptions about how your actions look like. I.e., also not that they have a type property. I somewhat like that. I could keep it that decoupled. Maybe I (we) can come up with an API that would keep this logic outside of the main lib but would still allow for grouping (because I like the sound of that).

@mrcoles
Copy link
Author

mrcoles commented Oct 2, 2023

Agree, a generic function that assumes nothing about actions sounds best!

The redux-undo one takes an optional function of this type:

type GroupByFunction<S = any, A extends Action = AnyAction> = (action: A, currentState: S, previousHistory: StateWithHistory<S>) => any;

and it uses the return value as a groupBy key, unless the value is null, then it assumes it’s not grouping (IDK if undefined should be treated the same too?).

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