react-exo-hooks
Version:
A collection of useful hooks for data structures and logic, designed for efficiency
85 lines (84 loc) • 2.38 kB
TypeScript
/**
* This is an array that causes rerenders on updates
* @note Effects and memos that use this array should also listen for its signal: `+INSTANCE`
*/
export declare class StatefulArray<T> extends Array<T> {
/** The dispatch function for the signal */
private readonly _dispatchSignal?;
/** The update signal */
private _signal;
/** THe dispatch function for redefining the array */
private _dispatchRedefine?;
/**
* Construct a StatefulArray
* @param initial The initial value (parameter for a vanilla array)
* @param dispatchSignal The dispatch function for the signal
*/
constructor(initial?: Iterable<T>, dispatchSignal?: StatefulArray<T>['_dispatchSignal']);
/**
* Set the redefine dispatch
* @private
* @param callback The function
*/
_setRedefine(callback: StatefulArray<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 there's no redefinition callback defined
*/
reset(value: Iterable<T>): Iterable<T>;
/**
* @override
*/
copyWithin(target: number, start: number, end?: number): this;
/**
* @override
*/
fill(value: T, start?: number, end?: number): this;
/**
* @override
*/
pop(): T | undefined;
/**
* @override
*/
push(...items: T[]): number;
/**
* @override
*/
reverse(): T[];
/**
* @override
*/
shift(): T | undefined;
/**
* @override
*/
sort(compareFn?: ((a: T, b: T) => number)): this;
/**
* @override
* @overload
*/
splice(start: number, deleteCount?: number): T[];
/**
* @override
*/
unshift(...items: T[]): number;
/**
* Returns the array's signal. Used for effects and memos that use this array
* @returns A numeric signal
*/
valueOf(): number;
}
/**
* Use a stately array
* @note Any effects or memos that use this set should also listen for its signal (`+INSTANCE`)
* @param initial The initial array value
* @returns The stately array
*/
export declare function useArray<T>(initial?: Iterable<T>): StatefulArray<T>;