Polymer 3.0 中的去抖器
Debouncer in Polymer 3.0
如何在 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
}
);
但我不知道如何在 Polymer 3 中设置 400ms 去抖
async
模块有timeout
功能但需要导入
import {timeOut} from '@polymer/polymer/lib/utils/async.js';
this._debouncer = Debouncer.debounce(
this._debouncer, // initially undefined
timeOut.after(400),
() => {
// some code
}
);
如何在 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
}
);
但我不知道如何在 Polymer 3 中设置 400ms 去抖
async
模块有timeout
功能但需要导入
import {timeOut} from '@polymer/polymer/lib/utils/async.js';
this._debouncer = Debouncer.debounce(
this._debouncer, // initially undefined
timeOut.after(400),
() => {
// some code
}
);