用例
- 我有一个人或组列表(如在 FB Messenger 中)(左窗格)
- 当我换人时,我会加载消息(API 调用)。
- 如果我快速按下向下箭头,那么我不想为每个人进行 API 调用,而是只想加载我暂停并等待的人。
目前我正在去抖 300 毫秒来实现这一点。
handleSwitchKeyEvent: function() { if (this.pendingLoad) { // Still pending continue to debounce clearTimeout(this.pendingLoad); fn = this.loadContent; } else { // No longer pending - So load data immediately this.loadContent(); } // Delay the load this.pendingLoad = setTimeout(function () { clearTimeout(this.pendingLoad); this.pendingLoad = 0; fn && fn.call(this); }, 300); }
问题
- 当我在 Message1 时 - 已加载 M1 详细信息
- 当我快速按键时 - M2 将加载,然后下一条消息会发生反跳)
我想避免这种 M2 负载。我不确定是否可以在同一流程中混合去抖动和非去抖动