abon
Version:
Flexible state management for React 🚀
58 lines (57 loc) • 3.06 kB
TypeScript
import { ChangeListener, UnsubscribeFn, ValueHandler } from "./types";
/** Subscribe to and update a normal array. */
export declare class AbonArray<T> extends Array<T> {
constructor(initial?: Iterable<T>);
set(items: T[]): this;
/** Deletes items from the array */
delete(...items: T[]): this;
/**
* Appends new items to the end of the list and returns the new amonut of items.
* @param items New items to append.
*/
push(...items: T[]): number;
/**
* Inserts new items at the start of the list.
* @param items New items to insert at the start of the list.
*/
unshift(...items: T[]): number;
/** Removes the last item and returns it. */
pop(): T | undefined;
/** Removes the first item and returns it. */
shift(): T | undefined;
/** Reverse the items */
reverse(): this;
splice(start: number, deleteCount?: number | undefined): T[];
fill(value: T, start?: number | undefined, end?: number | undefined): this;
map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[];
/** Sorts the array */
sort(compareFn?: (a: T, b: T) => number): this;
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
filter<S extends T>(callbackfn: (value: T, index: number, array: T[]) => value is S): S[];
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
filter(callbackfn: (value: T, index: number, array: T[]) => unknown): T[];
subscribe(listener: ChangeListener<T[]>): UnsubscribeFn;
handle(handler: ValueHandler<T[]>): UnsubscribeFn;
get current(): T[];
set current(items: T[]);
use(): this;
useSubscription(listener: ChangeListener<T[]>, deps?: readonly any[]): void;
/** A read-only version of the instance (for typings). */
get readonly(): ReadonlyAbonArray<T>;
notify(): void;
static use<T>(initial?: () => T[], deps?: readonly any[]): AbonArray<T>;
static useRef<T>(initial?: () => T[], deps?: readonly any[]): AbonArray<T>;
}
interface ReadonlyAbonArray<T> extends Omit<AbonArray<T>, "set" | "delete" | "push" | "unshift" | "reverse" | "notify" | "readonly" | "use" | "current" | "fill" | "pop" | "splice" | "shift"> {
use(): ReadonlyAbonArray<T>;
readonly current: T[];
}
export {};