react-state-bucket
Version:
A lightweight and powerful package designed to manage states globally in React applications. It provides CRUD operations for your state data with ease, enabling developers to handle complex state management scenarios without the need for heavy libraries.
31 lines (28 loc) • 988 B
TypeScript
import { XVInstanceType, Infer } from 'xanv';
type StoreType = "memory" | "session" | "local" | "url" | "cookie";
type InitialBucketData = {
[key: string]: XVInstanceType;
};
type BucketOptions = {
store?: StoreType;
onChange?: (key: string, value: any) => void;
};
declare class Bucket<IT extends InitialBucketData> {
private initial;
private option;
private hooks;
private data;
readonly changes: Map<keyof IT, boolean>;
constructor(initial: IT, option?: BucketOptions);
subscribe(id: string, hook: Function): void;
unsubscribe(id: string): void;
set<T extends keyof IT>(key: T, value: Infer<IT[T]>, dispatch?: boolean): void;
get<T extends keyof IT>(key: T): any;
sets(state: {
[key in keyof IT]?: Infer<IT[key]>;
}): void;
get state(): { [key in keyof IT]: Infer<IT[key]>; };
get errors(): Map<keyof IT, string>;
}
export { Bucket as default };
export type { BucketOptions, InitialBucketData, StoreType };