如何在Polymer 3中正确编写去抖动器?
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()); }
这很好,但是我需要配置一些时间。例如,这就是我在Polymer 1中所做的事情
this.debounce("scroll",function() {
this.$$("#scrollThreshold").clearTriggers();
}.bind(this), 400);
和聚合物2
this._debouncer = Polymer.Debouncer.debounce(
this._debouncer, // initially undefined
Polymer.Async.timeOut.after(400),
() => {
// some code
}
);
但是我不知道如何在聚合物3中设置400毫秒去抖动
答案 0 :(得分:2)
async
模块具有timeout
功能,但是您需要导入它
import {timeOut} from '@polymer/polymer/lib/utils/async.js';
this._debouncer = Debouncer.debounce(
this._debouncer, // initially undefined
timeOut.after(400),
() => {
// some code
}
);