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

Updated timer to support continuous run (#1) #92

Merged
merged 9 commits into from
Jul 31, 2019
Merged

Conversation

mohitYogi
Copy link
Contributor

  • 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.

* 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.
Copy link
Owner

@walmik walmik left a 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.
Copy link
Owner

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.

Copy link
Contributor Author

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) {
Copy link
Owner

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.

Copy link
Contributor Author

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 )) {
Copy link
Owner

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.
@mohitYogi
Copy link
Contributor Author

Updated the code.

Copy link
Owner

@walmik walmik left a 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.

@@ -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()
Copy link
Owner

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.
Copy link
Owner

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
Copy link
Owner

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.
@mohitYogi
Copy link
Contributor Author

Updated files as per required.

@mohitYogi mohitYogi closed this Jul 31, 2019
@mohitYogi mohitYogi reopened this Jul 31, 2019
Copy link
Owner

@walmik walmik left a 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

@walmik walmik merged commit 9b7c862 into walmik:master Jul 31, 2019
mohitYogi added a commit to mohitYogi/timer.jquery that referenced this pull request Dec 5, 2020
* 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>
This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants