universal-model-angular
Version:
Universal model for Angular
46 lines (45 loc) • 2.37 kB
TypeScript
import { ComputedRef, Ref, StopHandle, UnwrapRef } from '@pksilen/reactive-js';
import { SubStateFlagWrapper } from './createSubState';
export declare type SubState = object & SubStateFlagWrapper;
export declare type State = {
[key: string]: SubState;
};
export declare type StateGetter = () => any;
export declare type SelectorsBase<T extends State> = {
[key: string]: (state: T) => any;
};
export declare type Selectors<T extends State, U extends SelectorsBase<T>> = {
[K in keyof U]: (state: T) => ReturnType<U[K]>;
};
declare type ComputedSelectors<T extends State, U extends SelectorsBase<T>> = {
[K in keyof U]: ComputedRef<ReturnType<U[K]>>;
};
declare type ReactiveState<T extends State> = T extends Ref ? T : UnwrapRef<T>;
export default class Store<T extends State, U extends SelectorsBase<T>> {
private readonly reactiveState;
private readonly reactiveSelectors;
private readonly stateStopWatches;
private readonly selectorStopWatches;
private readonly componentInstanceToUpdatesMap;
private updateCount;
constructor(initialState: T, selectors?: Selectors<T, U>);
getStateStopWatches<V extends new (...args: any[]) => any>(componentInstace: InstanceType<V>): Readonly<StopHandle[]> | undefined;
getSelectorStopWatches<V extends new (...args: any[]) => any>(componentInstace: InstanceType<V>): Readonly<StopHandle[]> | undefined;
getUpdateCount(): Readonly<number>;
getState(): ReactiveState<T>;
getSelectors(): ComputedSelectors<T, U>;
getStateAndSelectors(): [ReactiveState<T>, ComputedSelectors<T, U>];
useStateAndSelectors<V extends new (...args: any[]) => any>(componentInstance: InstanceType<V>, subStateOrStateGetterMap: {
[stateName: string]: SubState | StateGetter;
}, selectorMap: {
[key: string]: ComputedRef;
}): void;
useState<V extends new (...args: any[]) => any>(componentInstance: InstanceType<V>, subStateOrStateGetterMap: {
[key: string]: SubState | StateGetter;
}): void;
useSelectors<V extends new (...args: any[]) => any>(componentInstance: InstanceType<V>, selectorMap: {
[key: string]: ComputedRef;
}): void;
watch<V extends new (...args: any[]) => any>(componentInstance: InstanceType<V>, name: string, subStateOrStateGetterOrSelector: SubState | StateGetter | ComputedRef): StopHandle;
}
export {};