UNPKG

@nimel/directorr

Version:
146 lines (145 loc) 9.12 kB
import { Middleware as ReduxMiddleware } from 'redux'; export declare type Resolver<T = any> = (value: T | PromiseLike<T>) => void; export declare type Rejector = (reason?: any) => void; export declare type WhenCancel = (callback: () => void) => void; export declare type Executor<T = any> = (resolve: Resolver<T>, reject: Rejector, whenCancel: WhenCancel) => void; export interface PromiseCancelable<T = any> extends Promise<T> { cancel: () => void; } export interface DirectorrStoreClass { isReady?: boolean | SomeFunction; isError?: boolean; fromJSON?: (parsedClassInstance: any) => void; [key: string]: any; } export interface DirectorrStoreClassConstructor<I = DirectorrStoreClass, O = any> { new (options?: O): I; storeName?: string; storeInitOptions?: O; afterware?: Afterware; } export declare type SomeObject = Record<string, any>; export declare type SomeActionType = string | DirectorrStoreClassConstructor<any> | DecoratorValueTypedWithType<any, any, string>; export declare type ActionType = SomeActionType | SomeActionType[] | ActionType[]; export declare type DispatcherActionType = DecoratorValueTypedWithType<any, any, string>; export declare type Action<T = string, P = undefined> = undefined extends P ? { type: T; [extraProps: string]: any; } : { type: T; payload: P; [extraProps: string]: any; }; export declare type EffectsMap = Map<string, (string | symbol)[]>; export declare type DispatchEffects = (action: Action) => void; export declare type HydrateStoresToState = (directorr: DirectorrStores) => DirectorrStoresState; export declare type MergeStateToStores = (state: DirectorrStoreState, directorrStore: DirectorrStore) => void; export declare type SetStateToStore = MergeStateToStores; export declare type DispatchAction<A extends Action = Action> = <T extends A>(action: T) => T; export declare type GetFunction = () => any; export declare type SetFunction = (value: any) => void; export declare type SomeFunction = (...args: any[]) => any; export declare type BatchFunction = (f: SomeFunction) => SomeFunction; export declare type CreateActionFunction = <T = string, P = never>(type: T, payload?: P) => Action<T, P>; export declare type CreateActionTypeFunction = (actionType: ActionType) => string; export declare type FindNextMiddleware = (nextIndex: number, action: Action) => any; export declare type ReduxMiddlewareRunner = (action: Action) => any; export declare type Next = (action: Action) => void; export declare type Middleware = (action: Action, next: Next, store: DirectorrInterface) => void; export declare type Afterware = (action: Action, dispatchType: DirectorrInterface['dispatchType'], directorr: DirectorrInterface) => void; export declare type PayloadAfterware = (dispatchType: DirectorrInterface['dispatchType'], payload: Action['payload'], directorr: DirectorrInterface) => void; export interface MiddlewareAdapterInterface { run(action: Action): void; next: any; middleware: ReduxMiddleware | Middleware; } export interface BabelDescriptor extends PropertyDescriptor { initializer?: SomeFunction; } export declare type Initializer = (initObject: any, value: any, property: string, ctx: any, ...args: any[]) => any; export declare type Decorator = (target: any, property: string, descriptor?: BabelDescriptor, ...args: any[]) => void; export declare type DecoratorValueTyped<R = any> = <T extends Record<K, R>, K extends string>(target: T, property: K, descriptor?: BabelDescriptor, ...args: any[]) => void; export interface DecoratorValueTypedWithType<P = any, R extends (...args: any) => any = (...args: any) => any, C = string> extends DecoratorValueTyped<R> { type: C; createAction: (payload: P) => Action<C, P>; isAction: (action: any) => action is Action<string, P>; } export declare type SomeAction<A = any> = (...args: any[]) => A | Promise<A>; export declare type SomeEffect<A = any> = (arg: A) => any; export declare type CreateDecorator<A1 = any, A2 = any> = (arg1: A1, arg2?: A2) => Decorator; export declare type CreateDecoratorOneArgOption<A1 = any> = (arg?: A1) => Decorator; export declare type CreateDecoratorOneArg<A = any, D = Decorator> = (arg: A) => D; export declare type CreateDecoratorValueTypedEffect<A = any> = <P = any, T = string>(arg: A) => DecoratorValueTypedWithType<P, SomeEffect<P>, T>; export declare type CreatePropertyDecoratorFactory<A1 = any, A2 = any, P = any> = (arg1: A1, arg2?: A2) => DecoratorValueTyped<SomeEffect<P>>; export declare type CreateDecoratorValueTypedWithTypeAction<A = any> = <P = any>(arg: A) => DecoratorValueTypedWithType<P, SomeAction<P | null>>; export declare type CreateDecoratorValueTypedWithTypeActionTwoOptions<A1 = any, A2 = any> = <P = any, T = string>(arg1: A1, arg2?: A2) => DecoratorValueTypedWithType<P, SomeAction<P | null>, T>; export declare type CreateContext = (moduleName: string, arg1: any, arg2?: any) => any; export declare type ConvertDecorator<D = any> = (decorator: D, context: any) => D; export interface InitializerContext { actionType: string; property: string; } export declare type CheckObjectPattern = SomeObject; export declare type ConvertPayloadFunction = (payload: Action['payload']) => any; export declare type CheckPayloadFunc = (payload: Action['payload']) => boolean; export declare type CheckPayloadPropFunc = (payload: Action['payload'], prop: string) => boolean; export declare type CheckPayload = CheckObjectPattern | CheckPayloadFunc; export declare type CheckStateFunc = (payload: Action['payload'], store: any) => boolean; export declare type CheckState = CheckObjectPattern | CheckStateFunc; export declare type AddToPayload = (payload: Action['payload'], store: any) => any; export declare type MessageFunc = (sourceName: string, arg?: any, errorMessage?: any) => string; export declare type RunDispatcher = (args: any[], actionType: string, valueFunc: any, store: any, addToPayload: AddToPayload) => any; export declare type DispatchProxyAction = (action: Action, fromStore: any, toStore: any, property: string, actionType?: string) => void; export declare type AddDispatchAction = (fromStore: any, toStore: any, property: string, actionType?: string, dispatchAction?: DispatchProxyAction) => any; export declare type PayloadChecker = (payload: any, valueFunc: SomeFunction, args: [CheckPayload, ConvertPayloadFunction?]) => any; export declare type StateChecker = (payload: any, valueFunc: SomeFunction, store: any, args: [CheckState]) => any; export declare type ValueSetter = (initObject: any, value: any, payload: any, args: [SomeFunction]) => any; export declare type Configure = (config: { batchFunction?: BatchFunction; createAction?: CreateActionFunction; actionTypeDivider?: string; createActionType?: CreateActionTypeFunction; dispatchEffects?: DispatchEffects; hydrateStoresToState?: HydrateStoresToState; mergeStateToStore?: MergeStateToStores; setStateToStore?: SetStateToStore; }) => void; export declare type DirectorrStores = Map<string, any>; export declare type DirectorrStore = DirectorrStoreClass; export declare type JSONLikeData = string | number | boolean | DirectorrStoreState; export interface DirectorrStoreState { [key: string]: JSONLikeData; } export interface DirectorrStoresState { [key: string]: DirectorrStoreState; } export declare type DepencyName = symbol | SomeObject; export interface DirectorrOptions { initState?: DirectorrStoresState; context?: SomeObject; } export interface DirectorrInterface { addStores(storeConstructors: DirectorrStoreClassConstructor<any>[]): void; addStore<I>(storeConstructor: DirectorrStoreClassConstructor<I>): I; removeStore(storeConstructor: DirectorrStoreClassConstructor<any>): void; addReduxMiddlewares: (middlewares: ReduxMiddleware[]) => void; addMiddlewares: (middlewares: Middleware[]) => void; removeMiddleware: (middleware: Middleware) => void; dispatch: DispatchAction; dispatchType: (type: string, payload?: any) => Action; getStore<C>(StoreConstructor: DirectorrStoreClassConstructor<C>): C | undefined; getHydrateStoresState: () => DirectorrStoresState; mergeStateToStore: (storeState: DirectorrStoresState) => void; setStateToStore: (storeState: DirectorrStoresState) => void; waitAllStoresState: (checkStoreState?: CheckStoreState) => PromiseCancelable<any>; waitStoresState: (stores: DirectorrStoreClassConstructor<any>[], checkStoreState?: CheckStoreState) => PromiseCancelable<any>; findStoreState: (checkStoreState?: CheckStoreState) => PromiseCancelable<any>; addStoreDependency<I>(StoreConstructor: DirectorrStoreClassConstructor<I>, depName: DepencyName): I; removeStoreDependency(StoreConstructor: DirectorrStoreClassConstructor<any>, depName: DepencyName): void; } export declare type SubscribeHandler = (store: DirectorrStores, action: Action) => void; export declare type UnsubscribeHandler = () => void; export declare type CheckStoreState = (someCalss: DirectorrStoreClass) => boolean; export interface InitPayload { store: DirectorrStoreClass; }