Skip to content

Commit

Permalink
update debounce example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Apr 21, 2017
1 parent 36792f9 commit 5be7ec9
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/utils/debounce.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5be7ec9

Please sign in to comment.