UNPKG

@sv-use/core

Version:

A collection of Svelte 5 utilities.

33 lines (32 loc) 1.33 kB
import type { Getter, Setter } from '../__internal__/types.js'; type HistorySnapshot<T> = { snapshot: T; timestamp: number; }; export type TrackHistoryOptions = { /** * Whether to include the current value in the history. * @default false */ includeCurrent?: boolean; }; export type TrackHistoryReturn<T> = { readonly canUndo: boolean; readonly canRedo: boolean; readonly history: HistorySnapshot<T>[]; /** @note It gets cleared if the original value changes unless it was changed via {@link TrackHistoryReturn.undo | `undo`} or {@link TrackHistoryReturn.redo | `redo`}. */ readonly redoHistory: HistorySnapshot<T>[]; /** @note It doesn't do anything if {@link TrackHistoryReturn.canUndo | `canUndo`} is `false`. */ undo(): void; /** @note It doesn't do anything if {@link TrackHistoryReturn.redo | `redo`} is `false`. */ redo(): void; }; /** * Tracks the change history of a reactive value. * @param value The value to track. * @param set The setter function to update the value. * @param options Additional options to customize the behavior. * @see https://svelte-librarian.github.io/sv-use/docs/core/track-history */ export declare function trackHistory<T>(value: Getter<T>, set: Setter<T>, options?: TrackHistoryOptions): TrackHistoryReturn<T>; export {};