stunk
Version:
Stunk is a lightweight, framework-agnostic state management library for JavaScript and TypeScript. It uses chunk-based state units for efficient updates, reactivity, and performance optimization in React, Vue, Svelte, and Vanilla JS/TS applications.
46 lines (40 loc) • 1.24 kB
TypeScript
import { M as Middleware, C as Chunk } from '../core-C7jFiHdO.js';
declare const logger: Middleware<any>;
declare const nonNegativeValidator: Middleware<number>;
interface ChunkWithHistory<T> extends Chunk<T> {
/**
* Reverts to the previous state (if available).
*/
undo: () => void;
/**
* Moves to the next state (if available).
*/
redo: () => void;
/**
* Returns true if there is a previous state to revert to.
*/
canUndo: () => boolean;
/**
* Returns true if there is a next state to move to.
*/
canRedo: () => boolean;
/**
* Returns an array of all the values in the history.
*/
getHistory: () => T[];
/**
* Clears the history, keeping only the current value.
*/
clearHistory: () => void;
}
declare function withHistory<T>(baseChunk: Chunk<T>, options?: {
maxHistory?: number;
}): ChunkWithHistory<T>;
interface PersistOptions<T> {
key: string;
storage?: Storage;
serialize?: (value: T) => string;
deserialize?: (value: string) => T;
}
declare function withPersistence<T>(baseChunk: Chunk<T>, options: PersistOptions<T>): Chunk<T>;
export { logger, nonNegativeValidator, withHistory, withPersistence };