UNPKG

react-exo-hooks

Version:

A collection of useful hooks for data structures and logic, designed for efficiency

68 lines (67 loc) 2.21 kB
/** * This is a set that causes rerenders on updates * @note Effects and memos that use this set should also listen for its signal: `+INSTANCE` */ export declare class StatefulMap<K, T> extends Map<K, T> { /** The dispatch function for the signal */ private readonly _dispatchSignal?; /** The update signal */ private _signal; /** THe dispatch function for redefining the set */ private _dispatchRedefine?; /** * Construct a StatefulSet * @param initial The initial value (parameter for a vanilla set) * @param dispatchSignal The dispatch function for the signal */ constructor(initial?: Map<K, T> | Array<[K, T]>, dispatchSignal?: StatefulMap<K, T>['_dispatchSignal']); /** * Set the redefine dispatch * @private * @param callback The function */ _setRedefine(callback: StatefulMap<K, T>['_dispatchRedefine']): void; /** * Force a signal update */ forceUpdate(): void; /** * Set the instance to an entirely new instance * @param value The new instance * @returns The new instance * @throws {Error} If no redefinition callback is defined */ reset(value: Map<K, T>): Map<K, T>; /** * @override */ set(key: K, value: T): this; /** * Bulk set an array of items * @note Always rerenders * @param items An array of items * @param keyFn Either the name of a property of each item or a function that returns the key for each item * @returns this */ bulkSet<U extends K & keyof T>(items: T[], keyFn: U | ((i: T) => U)): this; /** * @override */ delete(key: K): boolean; /** * @override */ clear(): void; /** * Returns the set's signal. Used for effects and memos that use this set * @returns The numeric signal */ valueOf(): number; } /** * Use a stately set * @note Any effects or memos that use this set should also listen for its signal (`+INSTANCE`) * @param initial The initial set value * @returns The stately set */ export declare function useMap<K, T>(initial?: Map<K, T> | Array<[K, T]>): StatefulMap<K, T>;