Add feature: allow the option to pass an array of consecutive delay values to the delay option of useTimer#22
Open
bouzidanas wants to merge 16 commits intojustinmahar:masterfrom
Open
Add feature: allow the option to pass an array of consecutive delay values to the delay option of useTimer#22bouzidanas wants to merge 16 commits intojustinmahar:masterfrom
delay option of useTimer#22bouzidanas wants to merge 16 commits intojustinmahar:masterfrom
Conversation
Author
|
I forgot to mention that the changes I made (additions) should not be breaking changes. In fact, I structured the code I added so that it is clear the previous code gets executed when the new options are not used. I also updated a bunch of packages so there should be 0 vulnerabilities. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many playback elements (that might have use for a precision timer) have a set of fixed known timestamps where events or UI changes are triggered. Things like slides, carousels, video sections, etc. Setting up the timer so that delay changes while the timer is playing (without interrupting the timer) can create challenges and code/render overhead.
For example, in one of my projects, I tried various options and I did end up with working solutions. However, I realized that all the code I added to my components render functions really belong inside of the useTimer! My solution looked a lot like I was working around the constraints/limitations of useTimer instead of my application. My workaround also made my code harder to maintain and harder to follow, etc.
So I solved my issues in a better way by adding a couple of features to
useTimer:options.delay. So now:This required changes to how
delayis set and changes to the useEffect that fires the callback.2. Added an argument to the
start()function to allow changing starting position in the delay array. This allows for navigating to different timestamps in my app.Note: I originally also added a
startIndextoTimerOptionsbut later removed it because it promotes poor/inefficient solutions such as creating a newuseTimer(with new startIndex) just to change play position. The better way is to provide adelayIndexvalue to thestartfunction. Like for example,With these added features I was able to maintain a single stable timer object while changing delays during uninterupted play.
Because this was useful to me and likely useful in many other scenerios, I thought I would make this pull request so that others may benefit from this open-source react utility library.