diff --git a/lib/utils/debounce.html b/lib/utils/debounce.html index 1507faa20a..48efe629a5 100644 --- a/lib/utils/debounce.html +++ b/lib/utils/debounce.html @@ -40,6 +40,7 @@ this._timer = this._asyncModule.run(() => { this._timer = null; this._callback(); + debouncerQueue.delete(this); }); } /** @@ -115,5 +116,36 @@ /** @const */ Polymer.Debouncer = Debouncer; + + let debouncerQueue = new Set(); + + /** + * Adds a `Debouncer` to a list of globally flushable tasks. + * + * @param {!Debouncer} debouncer Debouncer to enqueue + * @return {void} + */ + Polymer.enqueueDebouncer = function(debouncer) { + if (debouncerQueue.has(debouncer)) { + debouncerQueue.delete(debouncer); + } + debouncerQueue.add(debouncer); + }; + + Polymer.flushDebouncers = function() { + const didFlush = Boolean(debouncerQueue.size); + debouncerQueue.forEach(debouncer => { + try { + debouncer.flush(); + } catch(e) { + setTimeout(() => { + throw e; + }); + } + }); + debouncerQueue = new Set(); + return didFlush; + }; + })(); diff --git a/lib/utils/flush.html b/lib/utils/flush.html index 3feaad6166..0ab98780cd 100644 --- a/lib/utils/flush.html +++ b/lib/utils/flush.html @@ -8,37 +8,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> +