import type { AnyEventCreator, EmptyEventCreator, EventCreator1, Event } from './events'; import type { AnyAction, TramvaiAction } from './actions'; export type EmptyEventHandler = (state: State) => State; export type EventHandler = (state: State, payload: Payload) => State; export type EventHandlersToEventCreators; }> = { [K in keyof Model]: Model[K] extends EmptyEventHandler ? EmptyEventCreator : Model[K] extends EventHandler ? EventCreator1 : null; }; /** * @deprecated */ export type BaseStoreConstructor = { storeName: Name; handlers: Record; new (dispatcher: any): BaseStore; }; /** * @deprecated */ export interface BaseStore { state: Readonly; hydrateKeys: Record; dispatcher?: Readonly>; getState(): State; dehydrate(): Partial | void; rehydrate(state: State): void; } export interface ReduceBaseStore { getState(): State; dehydrate(): Partial | void; rehydrate(state: Partial | void): void; handle(payload: any, eventName: string, meta?: any): any; } export interface Reducer { storeName: Name; handlers: Record; events: Events; new (): ReduceBaseStore; on(event: AnyEventCreator | string | Array, handler: EventHandler): this; /** * @deprecated Use object initializer for the createReducer call to define events */ createEvents; }>(model: Model): EventHandlersToEventCreators; } export type StoreInstance = InstanceType; export interface GetState { (): Record; (reducer: Reducer): S; } export interface SubscribeHandler { (handler: (state: Record) => void): () => void; (reducer: Reducer, callback: (state: S) => void): () => void; } export type Dispatch = (event: Event) => Payload; export interface ConsumerContext { executeAction(action: TramvaiAction, ...params: Params): Result extends Promise ? Result : Promise; executeAction = any>(action: AnyAction, payload?: Payload): Promise ? U : Result>; dispatch: (actionOrNameEvent: string | Event, payload?: Payload) => Promise; dispatchWith: Event | Event = (...args: unknown[]) => Event | Event, Options extends Record = Record>(createActionOrType: CreateActionOrType, options?: Options) => (...args: any[]) => Promise; getState: GetState; /** * @deprecated используйте метод `context.getState(reducer)` */ getStore | BaseStoreConstructor | string | { store: Reducer | BaseStoreConstructor | string; optional: true; }, State = any>(store: Store): Store extends Reducer | BaseStoreConstructor ? InstanceType : { getState: () => State; setState: (state: State) => void; }; subscribe(callback: (state: Record) => void): () => void; subscribe(reducer: Reducer, callback: (state: S) => void): () => void; hasStore(store: Reducer | BaseStoreConstructor | string): boolean; registerStore(store: Reducer): void; unregisterStore(store: Reducer): void; } export interface StoreClass { handlers: Record; storeName: string; dependencies?: Array; new (dispatcher: DispatcherContext['dispatcherInterface']): any; } export type DispatcherContext = { getStore(storeClass: T | string | { store: T | string; optional: true; }): InstanceType | null; getState: GetState; subscribe: SubscribeHandler; dispatch: Dispatch; dispatcherInterface: { getContext: () => TContext; getStore: DispatcherContext['getStore']; }; }; export interface MiddlewareApi { dispatch: Dispatch; subscribe: SubscribeHandler; getState: GetState; } export type Middleware = (api: MiddlewareApi) => (next: Dispatch) => (event: Event) => any; //# sourceMappingURL=state.d.ts.map