-
Notifications
You must be signed in to change notification settings - Fork 85
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
Updated timer to support continuous run (#1) #92
Conversation
* Updated intervalHandler to support continuous run intervalHandler is updated in order to support continuous timer run, even after duration is completed * Flag for single call to callback Flag for single call to callback when timer completes in continuous run. * Update utils.js * support continuous Timer run 1. Added stopTimerOnDuration in config to run timer continuously. 2. Updated intervalHandler to support continuous run 3. Added Flag isCallbackCalled to stop multiple calls to callback after reaching the duration in continuous run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please bump patch version in package.json as part of this PR. Make it 0.9.1
.
src/utils.js
Outdated
@@ -52,7 +52,8 @@ function getDefaultConfig() { | |||
repeat: false, // This will repeat callback every n times duration is elapsed | |||
countdown: false, // If true, this will render the timer as a countdown (must have duration) | |||
format: null, // This sets the format in which the time will be printed | |||
updateFrequency: 500 // How often should timer display update | |||
updateFrequency: 500, // How often should timer display update | |||
stopTimerOnDuration: true, // If set to false than timer will keep on running even after duration is completed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this prop used anywhere? By the way, we do have a prop called repeat
to do this. Hence we might not need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the prop stopTimerOnDuration.
src/utils.js
Outdated
if (timerInstance.totalSeconds === 0) { | ||
|
||
//Added isCallbackCalled flag, to avoid multiple calls to the callback. | ||
if (!timerInstance.isCallbackCalled && timerInstance.totalSeconds === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the check for isCallbackCalled
? We are clearing the interval on the next line. Once the interval is cleared the callback
should not be called. Here s an example usage of the countdown with duration https://jsbin.com/noyijuqice/edit?js,console,output Lemme know if I m missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the flag.
if (timerInstance.totalSeconds > 0 && | ||
timerInstance.totalSeconds % timerInstance.config.duration === 0) { | ||
(timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good check to add :)
1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review.
Removed flag isCallbackCalled. (Not required).
1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review.
1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review.
New rule for checking timer duration completed.
Updated the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost there, left a coupla minor comments. Once you address those I ll merge the changes.
dist/timer.jquery.js
Outdated
@@ -241,7 +241,7 @@ function intervalHandler(timerInstance) { | |||
if (timerInstance.totalSeconds === 0) { | |||
clearInterval(timerInstance.intervalId); | |||
setState(timerInstance, Constants.TIMER_STOPPED); | |||
timerInstance.config.callback(); | |||
timerInstance.config.callback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the semi-colon got removed here in the dist file.
src/utils.js
Outdated
@@ -227,7 +227,8 @@ function intervalHandler(timerInstance) { | |||
|
|||
if (timerInstance.config.countdown) { | |||
timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; | |||
|
|||
|
|||
//Added isCallbackCalled flag, to avoid multiple calls to the callback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this comment as well.
src/utils.js
Outdated
if (!timerInstance.config.duration) { | ||
return; | ||
} | ||
|
||
// If the timer was called with a duration parameter, | ||
// run the callback if duration is complete | ||
// and remove the duration if `repeat` is not requested | ||
|
||
// Added new Condition of checking the timer completed or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this new comment and update the comment on line 250. Change from,
// run the callback if duration is complete
to,
// run the callback if duration is complete or total seconds is more than duration
Added missing semi colon. Updated Comment.
Updated files as per required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for diligent effort in getting this in. I m merging it now, it should be available on CDNjs. Currently it shows the existing version, but in a few hours it should update to the new version and will have your changes in it https://cdnjs.com/libraries/timer.jquery
* Updated timer to support continuous run (#1) (walmik#92) * Updated timer to support continuous run (#1) * Updated intervalHandler to support continuous run intervalHandler is updated in order to support continuous timer run, even after duration is completed * Flag for single call to callback Flag for single call to callback when timer completes in continuous run. * Update utils.js * support continuous Timer run 1. Added stopTimerOnDuration in config to run timer continuously. 2. Updated intervalHandler to support continuous run 3. Added Flag isCallbackCalled to stop multiple calls to callback after reaching the duration in continuous run. * Updates after review. 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. * Update after Review Removed flag isCallbackCalled. (Not required). * Updates after review 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. * Updates after Review 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. * Patch version New rule for checking timer duration completed. * Update timer.jquery.js * Semicolon & Comment update Added missing semi colon. Updated Comment. * Removed & Updated Comment * Update README.md (walmik#99) Let's not send people to an ad-infested abandoned domain name :) Co-authored-by: Alan <my@working.name>
intervalHandler is updated in order to support continuous timer run, even after duration is completed
Flag for single call to callback when timer completes in continuous run.
Update utils.js
support continuous Timer run