Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Clears any existing timer before assigning a new one in onTimer_() me…
Browse files Browse the repository at this point in the history
…thod to avoid previously scheduled callbacks.

RELNOTES: n/a

PiperOrigin-RevId: 368028553
  • Loading branch information
Closure Team authored and kjin committed Apr 14, 2021
1 parent 6c84afc commit 8170833
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions closure/goog/async/debouncer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ goog.async.Debouncer.prototype.fire = function(var_args) {
*/
goog.async.Debouncer.prototype.stop = function() {
'use strict';
if (this.timer_) {
goog.Timer.clear(this.timer_);
this.timer_ = null;
}
this.clearTimer_();
this.refireAt_ = null;
this.shouldFire_ = false;
this.args_ = [];
Expand Down Expand Up @@ -177,6 +174,7 @@ goog.async.Debouncer.prototype.disposeInternal = function() {
*/
goog.async.Debouncer.prototype.onTimer_ = function() {
'use strict';
this.clearTimer_();
// There is a newer call to fire() within the debounce interval.
// Reschedule the callback and return.
if (this.refireAt_) {
Expand All @@ -185,7 +183,6 @@ goog.async.Debouncer.prototype.onTimer_ = function() {
this.refireAt_ = null;
return;
}
this.timer_ = null;

if (!this.pauseCount_) {
this.doAction_();
Expand All @@ -195,6 +192,19 @@ goog.async.Debouncer.prototype.onTimer_ = function() {
};


/**
* Cleans the initialized timer.
* @private
*/
goog.async.Debouncer.prototype.clearTimer_ = function() {
'use strict';
if (this.timer_) {
goog.Timer.clear(this.timer_);
this.timer_ = null;
}
};


/**
* Calls the callback.
* @private
Expand Down

0 comments on commit 8170833

Please sign in to comment.