UNPKG

simple-object-state

Version:

An experiemental object oriented state mangment lib

28 lines (27 loc) 1.14 kB
import { Store } from "./Store"; export declare type ListenerCallback<State> = (state: State) => void; export declare type ClassConstructor<Type> = new () => Type; export declare class SimpleObjectStateStoreWrapper<StoreClass extends Store<State, Actions>, State, Actions> { Class: ClassConstructor<StoreClass>; Listeners: Array<ListenerCallback<State>>; Instance: StoreClass | undefined; private isCreatedThroughSub; /** * Initalize with the Class of the Store, we will setup the * store itself later with .Instance and .create() */ constructor(Class: ClassConstructor<StoreClass>); /** Just remove the instance, keep the class as we might re-instantiate */ destructor(): void; /** * Actually setup the store, at this point we would want * the stores state to be changing on subscribed to */ create(): StoreClass; getInstance(): StoreClass | undefined; callAction(action: string, args: any): void; onSetState(): void; getState(): State; subscribe(callback: ListenerCallback<State>): void; unsubscribe(callback: ListenerCallback<State>): void; }