From 5be7ec99c8bd517687483d2732b91a737fee929a Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 20 Apr 2017 17:34:41 -0700 Subject: [PATCH] update debounce example. --- lib/utils/debounce.html | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/utils/debounce.html b/lib/utils/debounce.html index 636af2cc15..6ca175fc04 100644 --- a/lib/utils/debounce.html +++ b/lib/utils/debounce.html @@ -68,19 +68,28 @@ } /** * Creates a debouncer if no debouncer is passed as a parameter - * or it cancels an active debouncer otherwise. For example, the following - * code can be called multiple times within a microtask and the provided - * function will be debounced (called once at the next microtask checkpoint): + * or it cancels an active debouncer otherwise. The following + * example shows how a debouncer can be called multiple times within a + * microtask and "debounced" such that the provided callback function is + * called once. Add this method to a custom element: * - * let job = Polymer.Debouncer.debounce(job, Polymer.Async.microTask, () => { - * console.log('debounced!'); - * }); + * _debounceWork() { + * this._debounceJob = Polymer.Debouncer.debounce(this._debounceJob, + * Polymer.Async.microTask, () => { + * this._doWork(); + * }); + * } + * + * If the `_debounceWork` method is called multiple times within the same + * microtask, the `_doWork` function will be called only once at the next + * microtask checkpoint. * * Note: In testing it is often convenient to avoid asynchrony. To accomplish * this with a debouncer, you can use `Polymer.enqueueDebouncer` and * `Polymer.flush`. For example, extend the above example by adding - * `Polymer.enqueueDebouncer(job)`. Then in a test, call `Polymer.flush` to - * ensure the debouncer has completed. + * `Polymer.enqueueDebouncer(this._debounceJob)` at the end of the + * `_debounceWork` method. Then in a test, call `Polymer.flush` to ensure + * the debouncer has completed. * * @param {Polymer.Debouncer?} debouncer Debouncer object. * @param {!AsyncModule} asyncModule Object with Async interface