@felte/common
Advanced tools
Comparing version
@@ -1,7 +0,12 @@ | ||
function debounce(func, timeout) { | ||
function debounce(func, timeout, { onInit, onEnd } = {}) { | ||
let timer; | ||
return (...args) => { | ||
clearTimeout(timer); | ||
if (!timer) | ||
onInit === null || onInit === void 0 ? void 0 : onInit(); | ||
if (timer) | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { | ||
func.apply(this, args); | ||
timer = undefined; | ||
onEnd === null || onEnd === void 0 ? void 0 : onEnd(); | ||
}, timeout); | ||
@@ -8,0 +13,0 @@ }; |
@@ -345,3 +345,6 @@ import { Readable, Writable } from "svelte/store"; | ||
declare function isEqual(val1: unknown, val2: unknown): boolean; | ||
declare function debounce<T extends unknown[]>(this: any, func: (...v: T) => any, timeout?: number): (...args: T) => void; | ||
declare function debounce<T extends unknown[]>(this: any, func: (...v: T) => any, timeout?: number, { onInit, onEnd }?: { | ||
onInit?: () => void; | ||
onEnd?: () => void; | ||
}): (...args: T) => void; | ||
/** | ||
@@ -348,0 +351,0 @@ * @category Helper |
@@ -1,2 +0,5 @@ | ||
declare function debounce<T extends unknown[]>(this: any, func: (...v: T) => any, timeout?: number): (...args: T) => void; | ||
declare function debounce<T extends unknown[]>(this: any, func: (...v: T) => any, timeout?: number, { onInit, onEnd }?: { | ||
onInit?: () => void; | ||
onEnd?: () => void; | ||
}): (...args: T) => void; | ||
export { debounce }; |
{ | ||
"name": "@felte/common", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Common utilities for Felte packages", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
205956
0.64%2127
0.76%