MCPcopy
hub / github.com/witheve/Eve / debounce

Function debounce

src/util.ts:36–67  ·  view source on GitHub ↗
(fn:CB, wait:number, leading?:boolean)

Source from the content-addressed store, hash-verified

34}
35
36export function debounce<CB extends Function>(fn:CB, wait:number, leading?:boolean) {
37 let timeout, context, args;
38
39 let doFn = function doDebounced() {
40 timeout = undefined;
41 fn.apply(context, args);
42 context = undefined;
43 args = undefined;
44 }
45
46 let debounced:CB;
47 if(!leading) {
48 debounced = function(...argList) {
49 context = this;
50 args = argList;
51 if(timeout) {
52 window.clearTimeout(timeout);
53 }
54 timeout = window.setTimeout(doFn, wait);
55 } as any;
56 } else {
57 debounced = function(...argList) {
58 context = this;
59 args = argList;
60 if(!timeout) {
61 timeout = window.setTimeout(doFn, wait);
62 }
63 } as any;
64 }
65
66 return debounced;
67}
68
69export function unpad(str:string):string {
70 if(!str) return str;

Callers 4

EditorClass · 0.90
IDEClass · 0.90
applyMethod · 0.90
applyMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected