diff --git a/client/src/main.ts b/client/src/main.ts index e752664..f9e3ff0 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -47,7 +47,7 @@ const makeRipple = (position: [number, number], radius: number): void => { // event handlers -const throttle = (fn: (...x: X[]) => Y, ms: number) => { +const debounce = (fn: (...x: X[]) => Y, ms: number) => { let lastExecutedAt = -1 return (...x: X[]) => { const now = Date.now() @@ -58,7 +58,7 @@ const throttle = (fn: (...x: X[]) => Y, ms: number) => { } } -const at60fps = (fn: (...x: X[]) => Y) => throttle(fn, 1000 / 60) +const at60fps = (fn: (...x: X[]) => Y) => debounce(fn, 1000 / 60) // create a big ripple when touching the screen canvas.addEventListener('mousedown', at60fps((e) => { @@ -191,17 +191,6 @@ document.addEventListener('DOMContentLoaded', () => { loop() }) -const debounce = (fn: Function, ms: number) => { - let prev = 0 - return (...args: any[]) => { - const now = Date.now() - if (now - prev > ms) { - fn.apply(null, args) - prev = now - } - } -} - window.addEventListener('resize', debounce(() => { ctx.canvas.width = window.innerWidth ctx.canvas.height = window.innerHeight