From e8d2314476a3ddcd804ca5afe5881f6f717736d2 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 27 Feb 2019 15:08:40 -0800 Subject: [PATCH] Use set and clear debouncer upon completion. Fixes #5250 --- lib/utils/debounce.html | 32 ++++++++++++++++++++++++++++ lib/utils/flush.html | 30 ++------------------------ test/unit/debounce.html | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 28 deletions(-) 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 --> +