UNPKG

abon

Version:

Flexible state management for React 🚀

37 lines (36 loc) • 1.94 kB
import { ChangeListener, UnsubscribeFn, ValueHandler } from "./types"; import { Falsey } from "./utils"; /** Subscribe to and set the values of a `Set`. */ export declare class AbonSet<T> extends Set<T> { constructor(initial?: Iterable<T>); add(value: T): this; /** `Set.add` */ add(value: T, silent?: true): this; delete(value: T): boolean; /** `Set.delete` */ delete(value: T, silent?: true): boolean; /** Ensure that the values of the set has equal content to the passed iterable and notifies if there's a diff. */ set(values?: Iterable<T> | null | false): boolean; /** Ensure that the values of the set has equal content to the passed iterable without notifying. */ set(values?: Iterable<T> | null | false, silent?: true): boolean; /** Use iterables to add or remove values and notify subscribers if there's a diff. */ modify(add?: Iterable<T> | Falsey, remove?: Iterable<T> | Falsey): boolean; /** Use iterables to add or remove values without notifying subscribers. */ modify(add?: Iterable<T> | Falsey, remove?: Iterable<T> | Falsey, silent?: true): boolean; subscribe(callback: ChangeListener<this>): UnsubscribeFn; handle(handler: ValueHandler<this>): UnsubscribeFn; clear(): void; /** `Set.clear` */ clear(silent?: true): void; use(): this; useSubscription(listener: ChangeListener<this>, deps?: readonly any[]): void; useHandler(handler: ValueHandler<this>, deps?: readonly any[]): void; notify(): void; get readonly(): ReadonlyAbonSet<T>; static use<T>(initial?: () => Iterable<T>, deps?: readonly any[]): AbonSet<T>; static useRef<T>(initial?: () => Iterable<T>, deps?: readonly any[]): AbonSet<T>; } interface ReadonlyAbonSet<T> extends Omit<AbonSet<T>, "notify" | "clear" | "modify" | "set" | "delete" | "add" | "readonly" | "use"> { use(): ReadonlyAbonSet<T>; } export {};