This commit is contained in:
eewing
2026-02-17 14:10:16 -06:00
parent 2bca5834c5
commit cf73cd3b4c
11246 changed files with 1690552 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
export * from "./throttled.svelte.js";
+1
View File
@@ -0,0 +1 @@
export * from "./throttled.svelte.js";
+8
View File
@@ -0,0 +1,8 @@
import type { Getter, MaybeGetter } from "../../internal/types.js";
export declare class Throttled<T> {
#private;
constructor(getter: Getter<T>, wait?: MaybeGetter<number>);
get current(): T;
cancel(): void;
setImmediately(v: T): void;
}
+26
View File
@@ -0,0 +1,26 @@
import { useThrottle } from "../use-throttle/use-throttle.svelte.js";
import { watch } from "../watch/watch.svelte.js";
import { noop } from "../../internal/utils/function.js";
export class Throttled {
#current = $state();
#throttleFn;
constructor(getter, wait = 250) {
this.#current = getter(); // Immediately set the initial value
this.#throttleFn = useThrottle(() => {
this.#current = getter();
}, wait);
watch(getter, () => {
this.#throttleFn()?.catch(noop);
});
}
get current() {
return this.#current;
}
cancel() {
this.#throttleFn.cancel();
}
setImmediately(v) {
this.cancel();
this.#current = v;
}
}