Last active
August 14, 2016 22:06
-
-
Save coderatchet/5bcbe1eae2e47154258e5946462f2cc8 to your computer and use it in GitHub Desktop.
goog.async.Debouncer usage
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
//after a little messing around, I found out how to use the goog.async.Debouncer properly | |
goog.require('goog.async.Debouncer'); | |
goog.require('goog.events.InputHandler'); | |
var usernameField_ = /* something like a textfield */ | |
var thingThatShouldHappenOnceAfterInterval = function(){ /* ... */ } | |
var inputHandler = new goog.events.InputHandler(userNameField_); | |
var eventHandler_ = /* @type goog.events.EventHandler */ | |
/* where the magic happens */ | |
var debouncer = new goog.async.Debouncer(function(){ | |
this.thingThatShouldHappenOnceAfterInterval(); | |
console.log("do the thing only once eventually!"); | |
}, 5000 /* millis */ , this /* function context */); | |
eventHandler.listen(inputHandler, goog.events.EventType.INPUT, function(){ | |
debouncer.fire(); // lets the debouncer know the event happened, and restarts the timer for the handler func. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment