如何正确写聚合物3中的去抖器?
documentation
import {microTask} from '@polymer/polymer/lib/utils/async.js'; import {Debouncer} from '@polymer/polymer/lib/utils/debounce.js'; // ... _debounceWork() { this._debounceJob = Debouncer.debounce(this._debounceJob, microTask, () => this._doWork()); }
这很好,但我需要配置一些时间。例如,这就是我在聚合物1中所做的
this.debounce("scroll",function() { this.$$("#scrollThreshold").clearTriggers(); }.bind(this), 400);
this._debouncer = Polymer.Debouncer.debounce( this._debouncer, // initially undefined Polymer.Async.timeOut.after(400), () => { // some code } );
但我不知道如何在聚合物3中设置400毫秒的去抖动
这个 async 模块具有 timeout 但是你需要导入它
async
timeout
import {timeOut} from '@polymer/polymer/lib/utils/async.js'; this._debouncer = Debouncer.debounce( this._debouncer, // initially undefined timeOut.after(400), () => { // some code } );