INIT
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
export * from "./previous.svelte.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from "./previous.svelte.js";
|
||||
+11
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user