Skip to content

Commit f15eb36

Browse files
author
infinitnet
committed
fix for bug #1 - add debounced.cancel method
1 parent f09c8f2 commit f15eb36

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

rdo.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,19 @@ const displayRelevantDetails = (content, terms, sortType, showUnusedOnly) => {
9090

9191
const debounce = (func, wait) => {
9292
let timeout;
93-
return (...args) => {
93+
function debounced(...args) {
94+
const later = () => {
95+
clearTimeout(timeout);
96+
timeout = null;
97+
func.apply(this, args);
98+
};
99+
clearTimeout(timeout);
100+
timeout = setTimeout(later, wait);
101+
}
102+
debounced.cancel = function() {
94103
clearTimeout(timeout);
95-
timeout = setTimeout(() => func.apply(this, args), wait);
96104
};
105+
return debounced;
97106
};
98107

99108
const debouncedDisplayRelevantDetails = debounce(displayRelevantDetails, 1000);

0 commit comments

Comments
 (0)