Skip to content

Comments

Updated undo and redo to accept a number of steps#32

Merged
charkour merged 4 commits intocharkour:v2from
ivoilic:feature/undo-steps
Jan 17, 2022
Merged

Updated undo and redo to accept a number of steps#32
charkour merged 4 commits intocharkour:v2from
ivoilic:feature/undo-steps

Conversation

@ivoilic
Copy link
Contributor

@ivoilic ivoilic commented Dec 31, 2021

Summary:

This PR adds a new optional parameter to the undo and redo function which specifies a number of steps to undo/redo. This parameter is optional and defaults to 1 as you might expect. The same as with a single step undo/redo, a multistep undo/redo will on undo/redo as many steps as possible.

Why?:

Being able to change state back/forward by more than one step will allow for more complex interactions with the history.

Breaking Changes:

Unfortunately this update causes an issue when undo/redo are passed directly to onClick as in the previous documentation. By default the event is passed which throws a type error since the functions are now expecting a number as the first parameter.

Tests:

I've added some basic tests but further more detailed tests should be implemented eventually.

@charkour
Copy link
Owner

Hey @ivoilic, thanks for the PR!

I love this idea and will review it formally later today. Thanks!

@charkour charkour self-assigned this Dec 31, 2021
@charkour charkour added the enhancement New feature or request label Dec 31, 2021
Copy link
Owner

@charkour charkour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great! Thanks for the PR.

As for the breaking change, do you think it would be good to release v2 of zundo? Or is it small enough to keep it in v1? I'm leaning towards a v2.

@ivoilic
Copy link
Contributor Author

ivoilic commented Jan 1, 2022

v2 Makes sense. In that case any other potentially breaking changes you want to roll in at the same time? I can add the fix for #24 clear -> clearUndoHistory into this PR for example.

@charkour
Copy link
Owner

charkour commented Jan 1, 2022

Sure, that is fine with me! Thank you.

@ivoilic
Copy link
Contributor Author

ivoilic commented Jan 3, 2022

Unless you can see any other issues or last minute breaking features to add this good to merge once the other PR has been merged and released. 🙏

Comment on lines +12 to +13
undo: (steps?: number) => void;
redo: (steps?: number) => void;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm looking at this, could the parameter of undo and redo be something like options that is an object? Right now the object would be options: { steps?: number }, but I could see us expanding the options. That way we wouldn't have breaking changes in the future if we want to add more. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what other options it would make sense to add to these functions. If you can think of a few important ones than sure, otherwise in the future you could always add a second parameter that accepts an options object. Not having to pass on options object feels more streamlined to me.

Copy link
Owner

@charkour charkour Jan 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, can't think of any off-hand. I'm good with keeping this streamlined until there is actually a use for multiple parameters.

@charkour charkour changed the base branch from main to v2 January 8, 2022 17:40
@charkour charkour added this to the v2 milestone Jan 8, 2022
@charkour
Copy link
Owner

charkour commented Jan 9, 2022

Once you solve the conflicts, I can merge this into the v2 branch and release a beta package.

I am re-writing some of the package to have better typescript support in v2, and have changed some of the APIs slightly. I can tag you once I make a PR with the new API to get your feedback on it. Your awesome logo will be in the v2 readme (along with a link to your twitter or whatever profile you would like).

@ivoilic ivoilic force-pushed the feature/undo-steps branch from 176ddea to ea0375a Compare January 16, 2022 18:27
@ivoilic ivoilic requested a review from charkour January 16, 2022 18:43
Copy link
Owner

@charkour charkour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I'll release a beta package since there are a couple other changes I'd like in v2.

Really appreciate the work!

@charkour charkour merged commit 48c873c into charkour:v2 Jan 17, 2022
@charkour
Copy link
Owner

The beta has been published. Please let me know if there are any issues! npm i [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants