@snipsonian/observable-state
Version:
Observable-state snippets (redux-like)
41 lines (40 loc) • 1.68 kB
TypeScript
import { IStateObserverManager } from '../observer/createStateObserverManager';
import { IStateStorageConfig } from './stateStorage';
import { ITriggerParentNotifications, TNrOfParentNotificationLevelsToTrigger } from '../observer/extendNotificationsToTrigger';
export interface IObservableStateStore<State, StateChangeNotificationKey> extends Pick<IStateObserverManager<StateChangeNotificationKey>, 'registerObserver' | 'unRegisterObserver'> {
getState: IGetState<State>;
setState: ISetState<State, StateChangeNotificationKey>;
}
export interface IGetState<State> {
(): State;
}
export interface ISetState<State, StateChangeNotificationKey> {
(props: ISetStateProps<State, StateChangeNotificationKey>): void;
}
export interface ISetStateProps<State, StateChangeNotificationKey> {
newState: TNewState<State>;
notificationsToTrigger?: StateChangeNotificationKey[];
nrOfParentNotificationLevelsToTrigger?: TNrOfParentNotificationLevelsToTrigger;
context?: ISetStateContext;
}
export declare type TNewState<State> = State | TToNewState<State>;
export declare type TToNewState<State> = (currentState: State) => State;
export interface ISetStateContext {
title: string;
info?: object;
}
export interface IObservableStateStoreConfig<State> {
initialState: State;
logStateUpdates?: boolean;
logNotifiedObserverNames?: boolean;
storage?: IStateStorageConfig<State>;
onBeforeStateUpdate?: (props: {
prevState: State;
newState: State;
}) => State;
onAfterStateUpdate?: (props: {
prevState: State;
newState: State;
}) => void;
triggerParentNotifications?: ITriggerParentNotifications;
}