@yeger/debounce
Version:
A tiny TypeScript library for debouncing functions.
1 lines • 786 B
Source Map (JSON)
{"version":3,"file":"index.mjs","names":["timeout: any"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Debounce a callback with an optional delay.\n * @param cb - The callback that will be invoked.\n * @param delay - A delay after which the callback will be invoked.\n * @returns The debounced callback.\n */\nexport function debounce<Args extends any[]>(\n cb: (...args: Args) => void,\n delay?: number,\n): (...args: Args) => void {\n let timeout: any\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout)\n }\n timeout = setTimeout(() => cb(...args), delay)\n }\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,SACd,IACA,OACyB;CACzB,IAAIA;AACJ,SAAQ,GAAG,SAAe;AACxB,MAAI,YAAY,OACd,cAAa,QAAQ;AAEvB,YAAU,iBAAiB,GAAG,GAAG,KAAK,EAAE,MAAM"}