Files
welshman/packages/store/src/throttle.ts
T
2025-04-25 10:37:57 -07:00

13 lines
327 B
TypeScript

import {Readable, Subscriber} from "svelte/store"
import {throttle} from "@welshman/lib"
export const throttled = <T, S extends Readable<T>>(delay: number, store: S) => {
if (delay) {
const {subscribe} = store
store = {...store, subscribe: (f: Subscriber<T>) => subscribe(throttle(delay, f))}
}
return store
}