Skip to content

Commit 28b24f1

Browse files
committed
chore: move debounce to ./deps/underscore-plus.js
1 parent 8aed52c commit 28b24f1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/deps/underscore-plus.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,34 @@ export function dasherize(string) {
2222
}
2323
})
2424
}
25+
26+
export function debounce(func, wait, immediate) {
27+
var timeout, result;
28+
29+
var later = function(context, args) {
30+
timeout = null;
31+
if (args) result = func.apply(context, args);
32+
};
33+
34+
var debounced = function(...args) {
35+
if (timeout) clearTimeout(timeout);
36+
if (immediate) {
37+
var callNow = !timeout;
38+
timeout = setTimeout(later, wait);
39+
if (callNow) result = func.apply(this, args);
40+
} else {
41+
timeout = setTimeout(function() {
42+
func(...args);
43+
}, wait);
44+
}
45+
46+
return result;
47+
};
48+
49+
debounced.cancel = function() {
50+
clearTimeout(timeout);
51+
timeout = null;
52+
};
53+
54+
return debounced;
55+
}

lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import config from "./config.json"
77
import * as PluginManagement from "./plugin-management"
88
import { treeSitterWarning } from "./performance-monitor"
99
import DOMStylesReader from "./dom-styles-reader"
10-
import { debounce } from "underscore-plus"
10+
import { debounce } from "./deps/underscore-plus"
1111

1212
export { default as config } from "./config.json"
1313
export * from "./plugin-management"

0 commit comments

Comments
 (0)