/** * state.ts * * @package vrkd/object * @author Fernando Salazar */ import { type Obj } from "./objectTypes"; export declare const StateSym: unique symbol; export type Subscriber = (state: S) => void; /** * Interactions with state produces new object, promoting immutability. */ export declare class State { /** * Never access the state directly. */ private [StateSym]; private _subscriber; /** * Store constructor * * @param {object} $state * @param {object} $default version of state. */ constructor($state: S, $default?: S | null); /** * Merge a state into current state. * * @param {object} $state */ setState($state: Partial): void; /** * Always produce a copy of the state. * * @return The current state cloned. */ getState(): S; /** * Subscriber will fire with the latest state after each state change. * * @param subscriber */ subscribe(subscriber: Subscriber): void; /** * Read a state param without cloning the param. * * @param {string} $name * @return Param value */ protected _readStateParam($name: keyof S): S[keyof S]; }