Use case
- I have a list of person or group (like in FB messenger) (left pane)
- When I switch person, I load the message (API call).
- If I press down arrow quickly, then instead of making API call for each of the person, I want to load only the person who I pause and wait.
Currently I am debouncing 300ms to achieve this.
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); }
Problem
- When I am at Message1 - M1 details are loaded
- When I press key fast - M2 will load and then de-bounce will happen for the next message)
I want to avoid this M2 load. I am not sure whether that is even possible to mix debouce and non-debounce in the same flow