From cdc96e5ef1265b35441f5dcf59e8e93d4f1a304f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 14 Jun 2024 22:28:29 +0530 Subject: [PATCH] feat: throttle helper --- src/helpers/inputHelpers.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/helpers/inputHelpers.ts diff --git a/src/helpers/inputHelpers.ts b/src/helpers/inputHelpers.ts new file mode 100644 index 00000000..0d395ceb --- /dev/null +++ b/src/helpers/inputHelpers.ts @@ -0,0 +1,21 @@ +import { + ONE_PERCENT_OF_VIEWPORT_H, + ONE_PERCENT_OF_VIEWPORT_W, + VIEWPORT_W, + VIEWPORT_H, +} from "../constants/const"; +import { Coordinates } from '../components/atoms/canvas'; + +export const throttle = (callback: any, limit: number) => { + let wait = false; + return (...args: any[]) => { + if (!wait) { + callback(...args); + wait = true; + setTimeout(function () { + wait = false; + }, limit); + } + } +} +