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 an action that can remove slices of history #266

Open
1 of 4 tasks
nmay231 opened this issue Mar 11, 2020 · 2 comments
Open
1 of 4 tasks

Add an action that can remove slices of history #266

nmay231 opened this issue Mar 11, 2020 · 2 comments
Labels
enhancement question A question about the future of the project

Comments

@nmay231
Copy link
Collaborator

nmay231 commented Mar 11, 2020

I'm submitting a ...

  • Bug report
  • Feature request
  • Docs update
  • Support request => Please do not submit support requests here, see note at the top of this template.

What is the current behavior/state of the project?

There is currently no way to change existing history in .past and .future without completely clearing the history.

What is the desired behavior?

It might be useful to remove certain parts of history in the past or future array by dispatching an action. For example, an action could be dispatched to remove states at index 3 to 7 in the past array.

If this is a feature request, what is the use case for changing the behavior?

An end-user could be presented with a history of states and choose to "group" ranges of changes into one change. In the background, this would really be removing ranges of history.

And it could make history "housecleaning" easier. While it would be more desirable to achieve clean histories with filter and groupBy, it might be easier sometimes to just remove unwanted history after the fact.

Implementation and other information

The implementation that I can see as the most general would be action(s) defining an array splice operation. We could add two action creators: splicePast and spliceFuture. Both have the function signature similar to splice and return the following action:

(start, deleteCount = 1, ...newStates) => ({
  type: '@@redux-undo/splice',
  which: 'past' || 'future',
  start,
  deleteCount,
  newStates
})

Note: deleteCount does have a different default than Array.splice. I think it makes more sense for this case, but I'm not attached to using 1.

Even if this exact implementation is not used, something to be able to change existing history could be useful.

This is inspired by user @dannyharding10 in gitter.

@nmay231 nmay231 added enhancement question A question about the future of the project labels Mar 11, 2020
@danny-does-stuff
Copy link

danny-does-stuff commented May 12, 2020

iirc, my use case was that I was dispatching a 'save' action, which didn't modify the business part of the store, just the save state. When the end user would try to undo beyond this 'extra' action, it would look like nothing changed, when really they were undoing the "save" action. I was able to work around this with some funky grouping logic, but I would have preferred a feature like this 👍

@harishvenki
Copy link

Any update on this feature ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement question A question about the future of the project
Projects
None yet
Development

No branches or pull requests

3 participants