【问题标题】:Debouncer in Polymer 3.0Polymer 3.0 中的去抖器
【发布时间】:2018-09-27 09:53:51
【问题描述】:

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

但我不知道如何在 Polymer 3 中设置 400ms 去抖动

【问题讨论】:

    标签: polymer polymer-3.x


    【解决方案1】:

    async 模块有timeout 功能,但您需要导入它

    import {timeOut} from '@polymer/polymer/lib/utils/async.js';
    
    this._debouncer = Debouncer.debounce(
        this._debouncer, // initially undefined
        timeOut.after(400),
        () => {
           // some code
        }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      相关资源
      最近更新 更多