UNPKG

simple-object-state

Version:

An experiemental object oriented state mangment lib

40 lines (39 loc) 2.98 kB
import { SimpleObjectStateStoreWrapper, ClassConstructor, ListenerCallback } from "./SimpleObjectStateStoreWrapper"; import { Store } from "./Store"; /** Simple Object State Singleton */ declare class SimpleObjectState { static Instance: SimpleObjectState; private Stores; private debug; constructor(); destroyStore: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => void; getState: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => State | undefined; createStore: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => void; callAction: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>, action: string, ...args: any) => void; /** Sets debug mode where a stack will be built of state updates */ setDebug(value: boolean): void; /** Returns the Store Class if one */ getClass: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => ClassConstructor<StoreClass> | undefined; /** Returns the Store Static Initial State if one */ getInitialState: <StoreClass extends Store<State, Actions> & { InitialState: State; }, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => State | undefined; /** Registers the Store, this will not actually instantiate the Store */ register: <StoreClass extends Store<State, Actions>, State, Actions>(Class: ClassConstructor<StoreClass>) => SimpleObjectStateStoreWrapper<any, any, any>; unregister: <StoreClass extends Store<State, Actions>, State, Actions>(Class: ClassConstructor<StoreClass>) => void; /** Subscribes a callback to a stores setState function */ subscribe: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>, callback: ListenerCallback<State>) => void; unsubscribe: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>, callback: ListenerCallback<State>) => void; /** Called by the Store when it sets its own state to call all subscribers */ onSetState: <StoreClass extends Store<State, Actions>, State, Actions>(This: StoreClass) => void; /** Returns the Store Instance if one */ getStore: <StoreClass extends Store<State, Actions>, State, Actions>(ref: string | StoreClass | ClassConstructor<StoreClass>) => StoreClass | undefined; /** Private */ /** Returns the Store Class if one */ private getString; /** Returns the Store Wrapper if on or creates if ref is a Class */ private getWrapper; private addStoreByClass; } declare const simpleObjectState: SimpleObjectState; export { simpleObjectState as SimpleObjectState };