Kub*_*ský 2 polymer polymer-3.x
如何在 Polymer 3 中正确编写 debouncer ?
根据文档
Run Code Online (Sandbox Code Playgroud)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);
Run Code Online (Sandbox Code Playgroud)
和聚合物 2
this._debouncer = Polymer.Debouncer.debounce(
this._debouncer, // initially undefined
Polymer.Async.timeOut.after(400),
() => {
// some code
}
);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在 Polymer 3 中设置 400 毫秒去抖动
该async模块具有timeout的功能,但你需要导入它
import {timeOut} from '@polymer/polymer/lib/utils/async.js';
this._debouncer = Debouncer.debounce(
this._debouncer, // initially undefined
timeOut.after(400),
() => {
// some code
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
765 次 |
| 最近记录: |