Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: third_party/polymer/v0_8/components-chromium/polymer/src/lib/debounce-extracted.js

Issue 1162563004: Upgrade to 1.0 and switch clients to dom-repeat where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a layout import and remove the gzipped webanimation in reproduce.sh Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1
2
3 Polymer.Debounce = (function() {
4
5 // usage
6
7 // invoke cb.call(this) in 100ms, unless the job is re-registered,
8 // which resets the timer
9 //
10 // this.job = this.debounce(this.job, cb, 100)
11 //
12 // returns a handle which can be used to re-register a job
13
14 var Async = Polymer.Async;
15
16 var Debouncer = function(context) {
17 this.context = context;
18 this.boundComplete = this.complete.bind(this);
19 };
20
21 Debouncer.prototype = {
22 go: function(callback, wait) {
23 var h;
24 this.finish = function() {
25 Async.cancel(h);
26 };
27 h = Async.run(this.boundComplete, wait);
28 this.callback = callback;
29 },
30 stop: function() {
31 if (this.finish) {
32 this.finish();
33 this.finish = null;
34 }
35 },
36 complete: function() {
37 if (this.finish) {
38 this.stop();
39 this.callback.call(this.context);
40 }
41 }
42 };
43
44 function debounce(debouncer, callback, wait) {
45 if (debouncer) {
46 debouncer.stop();
47 } else {
48 debouncer = new Debouncer(this);
49 }
50 debouncer.go(callback, wait);
51 return debouncer;
52 }
53
54 // exports
55
56 return debounce;
57
58 })();
59
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698