聚合物3.0中的去弹药

时间:2018-09-27 09:53:51

标签: polymer polymer-3.x

如何在Polymer 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());
}

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

1 个答案:

答案 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
    }
);