quantajs
Version:
A compact, scalable, and developer-friendly state management library designed for any JavaScript environment. It includes a reactivity system that enables efficient and flexible data handling, making complex state management easy.
43 lines (32 loc) • 1.36 kB
TypeScript
export declare type ActionDefinition<S extends object, G extends object, A> = {
[key in keyof A]: (this: StoreInstance<S, G, A>, ...args: any[]) => any;
} & ThisType<S & {
[K in keyof G]: G[K];
} & A>;
export declare const computed: <G>(getter: () => G) => {
readonly value: G;
};
export declare const createStore: <S extends object, G extends object, A extends Record<string, (...args: any[]) => any>>(name: string, options: {
state: StateDefinition<S>;
getters?: GetterDefinition<S, G>;
actions?: ActionDefinition<S, G, A>;
} & ThisType<S & { [K in keyof G]: G[K]; } & A>) => StoreInstance<S, G, A>;
export declare type GetterDefinition<S, G> = {
[key in keyof G]: (state: S) => G[key];
};
export declare const reactive: <S>(target: S) => S;
export declare type StateDefinition<S> = () => S;
export declare interface Store<S, G, A> {
state: S;
getters: G;
actions: A;
subscribe: (callback: StoreSubscriber) => () => void;
}
export declare type StoreInstance<S extends object, G extends Record<string, any>, A> = S & {
[K in keyof G]: G[K];
} & A & {
subscribe: (callback: StoreSubscriber) => () => void;
};
export declare type StoreSubscriber = () => void;
export declare const watch: <T>(source: () => T, callback: (value: T) => void) => void;
export { }