import Events from "./events.js"; import Logger from "./logger.js"; import { ILoggerOpts } from "./logger.js"; import Manager from "./manager.js"; import CombinedStorage from "./storages/combined-storage.js"; import StoreStatus from "./store-status.js"; interface IWindowManager { push: (state: Record) => void; } declare global { interface Window { mbxM: Record[] | IWindowManager; } } interface IConstructorParams { storeManager: Manager; getStore: (store: IConstructableStore, params?: Partial) => T | undefined; componentProps: TProps; initState?: Record; } interface IStoreLifecycle { init?: () => void | (() => void); onDestroy?: () => void; onComponentPropsUpdate?: (props: any) => void; } interface IStore extends IStoreLifecycle { libStoreId?: string; libStoreContextId?: string; libStoreParentId?: string; libStoreSuspenseId?: string; libStoreComponentName?: string; libStoreStatus?: StoreStatus; libDestroyTimer?: ReturnType; isGlobal?: boolean; toJSON?: () => Record; } interface IRelativeStore extends IStore { } interface IGlobalStore extends IStore { } interface IStorePersisted extends IStore { libStorageOptions?: IPersistOptions; addOnChangeListener?: (store: IStorePersisted, manager: Manager) => (() => void) | undefined; wakeup?: TWakeup; } type TInitStore = TSto & TAnyStore; type IConstructableStore = (new (props: IConstructorParams) => TInitStore) & Partial; /** * Store params */ type IStoreConfig = { id?: string; isParent?: boolean; }; type TStoreDefinition = IConstructableStore | ({ store: IConstructableStore; } & IStoreConfig); type TMapStores = Record; interface IManagerParams { storesParams?: Omit; storage?: IStorage | CombinedStorage; options?: IManagerOptions; initState?: Record; logger?: Logger | Omit; } type TWakeup = (state: { manager: Manager; initState?: Record; persistedState?: Record; }) => void; interface IStorage { get: () => Record | undefined | Promise | undefined>; set: (value: Record | undefined) => Record | undefined | Promise | void; flush: () => void | Promise; } interface IManagerOptions { shouldDisablePersist?: boolean; shouldRemoveInitState?: boolean; destroyTimers?: { init?: number; touched?: number; unused?: number; }; /** * When for some strange reason stores cannot be created or found in the parent context: * none: don't do anything * dummy: force create empty store * empty (default): don't render component if any of the stores not created */ failedCreationStrategy?: 'none' | 'dummy' | 'empty'; } type TAnyStore = IStore | IRelativeStore | IGlobalStore | IStorePersisted; type TStores = { [storeKey: string]: TAnyStore; }; /** * Convert class type to class constructor */ type ClassReturnType = T extends new (...args: any) => infer R ? R : T extends { store: any; } ? ClassReturnType : never; /** * Stores map to type */ type StoresType = { [keys in keyof TSt]: ClassReturnType; }; interface IStoreParams { id?: string; key?: string; contextId?: string; parentId?: string; suspenseId?: string; componentName?: string; componentProps?: Record; } interface IWithStoreOptions { customContextId?: string; } interface IMobxManagerEvents { [Events.CREATE_STORE]: { store: IConstructableStore; }; [Events.MOUNT_STORE]: { store: TAnyStore; }; [Events.UNMOUNT_STORE]: { store: TAnyStore; }; [Events.DELETE_STORE]: { store: TAnyStore; }; } interface IGroupedStores { relativeStores: TStores; parentStores: TStores; globalStores: TStores; hasCreationFailure: boolean; } interface IPersistOptions { behaviour?: 'exclude' | 'include'; attributes?: { [storageId: string]: string[]; }; isNotExported?: boolean; } export { IWindowManager, IConstructorParams, IStoreLifecycle, IStore, IRelativeStore, IGlobalStore, IStorePersisted, TInitStore, IConstructableStore, IStoreConfig, TStoreDefinition, TMapStores, IManagerParams, TWakeup, IStorage, IManagerOptions, TAnyStore, TStores, ClassReturnType, StoresType, IStoreParams, IWithStoreOptions, IMobxManagerEvents, IGroupedStores, IPersistOptions };