diff --git a/packages/runed/src/lib/utilities/Previous/Previous.svelte.ts b/packages/runed/src/lib/utilities/Previous/Previous.svelte.ts index 3dba7ab6..c3afbe5f 100644 --- a/packages/runed/src/lib/utilities/Previous/Previous.svelte.ts +++ b/packages/runed/src/lib/utilities/Previous/Previous.svelte.ts @@ -1,4 +1,5 @@ -import { type PreviousValue, watch } from "../index.js"; +import { untrack } from "svelte"; +import { watch } from "../index.js"; import type { Getter } from "$lib/internal/types.js"; /** @@ -7,17 +8,17 @@ import type { Getter } from "$lib/internal/types.js"; * @see {@link https://runed.dev/docs/utilities/use-previous} */ export class Previous { - #previous = $state | undefined>(); + #previous = $state(undefined); + #curr = $state(undefined); constructor(getter: Getter) { - // eslint-disable-next-line ts/no-explicit-any - this.#previous = (Array.isArray(getter()) ? [] : undefined) as any; - watch(getter, (_, prev) => { - this.#previous = prev; + $effect(() => { + this.#previous = untrack(() => this.#curr); + this.#curr = getter(); }); } get current() { return this.#previous; } -} +} \ No newline at end of file diff --git a/packages/runed/src/lib/utilities/watch/watch.svelte.ts b/packages/runed/src/lib/utilities/watch/watch.svelte.ts index 30720899..9f4931e2 100644 --- a/packages/runed/src/lib/utilities/watch/watch.svelte.ts +++ b/packages/runed/src/lib/utilities/watch/watch.svelte.ts @@ -31,7 +31,7 @@ export type WatchOptions = { once?: boolean; }; -export type PreviousValue = T extends Array ? Array : T | undefined; +type PreviousValue = T extends Array ? Array : T | undefined; function runWatcher( source: Getter,