UNPKG

abon

Version:

Flexible state management for React 🚀

39 lines (38 loc) • 2.37 kB
import { ChangeListener, UnsubscribeFn, ValueHandler } from "./types"; /** Subscribe to and set the entries of a `Map`. */ export declare class AbonMap<K, V> extends Map<K, V> { constructor(initial?: readonly (readonly [K, V])[] | null); set(key: K, value: V): this; /** Set the current entries, meaning entries that currently exist but do not exist in the passed `entries` will be deleted. */ set(entries: [K, V][]): this; /** Set the current entries, meaning entries that currently exist but do not exist in the passed `record` will be deleted. */ set(record: Record<K & keyof any, V>): this; /** Patch the current entries, meaning entries of the passed `entries` will be created or updated depending if they exist in the current entries. */ patch(entries: [K, V][]): this; /** Patch the current entries, meaning entries of the passed `record` will be created or updated depending if they exist in the current entries. */ patch(record: K extends keyof any ? Record<K & keyof any, V> : any): this; delete(key: K): boolean; subscribe(key: K, listener: ChangeListener<V>): UnsubscribeFn; subscribe(listener: ChangeListener<this>): UnsubscribeFn; handle(handler: ValueHandler<this>): UnsubscribeFn; handle(handler: ChangeListener<this>): UnsubscribeFn; use(key: K): V | undefined; use(): this; useSubscription(key: K, listener: ChangeListener<V>, deps?: readonly any[]): void; useSubscription(listener: ChangeListener<this>, deps?: readonly any[]): void; useHandler(key: K, handler: ValueHandler<V>): void; useHandler(handler: ValueHandler<this>): void; notify(keys?: K[]): void; clear(): void; get record(): K extends keyof any ? Record<K, V> : any; protected silentlySet(key: K, value: V): this; protected silentlyDelete(key: K): boolean; get readonly(): ReadonlyAbonMap<K, V>; static use<K, V>(initial?: () => readonly (readonly [K, V])[] | null, deps?: readonly any[]): AbonMap<K, V>; static useRef<K, V>(initial?: () => readonly (readonly [K, V])[] | null, deps?: readonly any[]): AbonMap<K, V>; } interface ReadonlyAbonMap<K, V> extends Omit<AbonMap<K, V>, "clear" | "notify" | "set" | "patch" | "delete" | "readonly" | "use"> { use(key: K): V | undefined; use(): ReadonlyAbonMap<K, V>; } export {};