Debouncer in Polymer 2.0

A simple question, but no documentation on this issue: is there a debouncer in Polymer 2.0? If so, how can it be used? this.debounce was an instance method in 1.0, but it seems to have disappeared.

Thanks in advance!

+8
polymer
source share
1 answer

Legacy Debugger 1.x

You can use the 1.x this.debounce() method with Polymer.LegacyElementMixin :

 class XFoo extends Polymer.LegacyElementMixin(Polymer.Element) { ... _onClick() { this.debounce('myDebouncer', callback, 2000); } } 

codepen

New 2.x debouncer 2.x

equivalent to 2.0 Polymer.Debouncer.debounce(debouncer, asyncModule, cb) , where:

This function returns an instance of Polymer.Debouncer that has a cancel() method equivalent to 1.x this.cancelDebouncer(JOB_NAME) . This instance must be passed to the debounce() method the next time it is called for debouncing to work properly.

Usage example:

 class XFoo extends Polymer.Element { ... _onClick() { this._debouncer = Polymer.Debouncer.debounce( this._debouncer, // initially undefined Polymer.Async.timeOut.after(2000), callback); } } 

codepen

+24
source share

All Articles