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 "./previous.svelte.js";
+1
View File
@@ -0,0 +1 @@
export * from "./previous.svelte.js";
+11
View File
@@ -0,0 +1,11 @@
import type { Getter } from "../../internal/types.js";
/**
* Holds the previous value of a getter.
*
* @see {@link https://runed.dev/docs/utilities/previous}
*/
export declare class Previous<T> {
#private;
constructor(getter: Getter<T>, initialValue?: T);
get current(): T | undefined;
}
+25
View File
@@ -0,0 +1,25 @@
/**
* Holds the previous value of a getter.
*
* @see {@link https://runed.dev/docs/utilities/previous}
*/
export class Previous {
#previousCallback = () => undefined;
#previous = $derived.by(() => this.#previousCallback());
constructor(getter, initialValue) {
let actualPrevious = undefined;
if (initialValue !== undefined)
actualPrevious = initialValue;
this.#previousCallback = () => {
try {
return actualPrevious;
}
finally {
actualPrevious = getter();
}
};
}
get current() {
return this.#previous;
}
}