Polymer 3.0 中的去抖动器

Kub*_*ský 2 polymer polymer-3.x

如何在 Polymer 3 中正确编写 debouncer ?

根据文档

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());
}
Run Code Online (Sandbox Code Playgroud)

这很好,但我需要配置一些时间。例如,这就是我在 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 毫秒去抖动

Hyy*_*her 5

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)