UNPKG

@lomray/react-mobx-manager

Version:
244 lines (243 loc) 6.28 kB
import Logger from "./logger.js"; import CombinedStorage from "./storages/combined-storage.js"; import StoreStatus from "./store-status.js"; import { IConstructableStore, IGroupedStores, IManagerOptions, IManagerParams, IPersistOptions, IStoreParams, IStorePersisted, TAnyStore, TInitStore, TStoreDefinition, TStores } from "./types.js"; /** * Mobx stores manager */ declare class Manager { /** * Manger instance */ protected static instance: Manager; /** * Created stores */ protected readonly stores: Map<string, TInitStore<import("./types.js").IStore>>; /** * Relations between stores */ protected readonly storesRelations: Map<string, { ids: Set<string>; parentId: string | null; componentName?: string | undefined; }>; /** * Save persisted stores identities */ protected static readonly persistedStores: Set<string>; /** * Initial stores state (local storage, custom etc.) */ protected readonly initState: Record<string, any>; /** * Storage for persisted stores */ readonly storage?: CombinedStorage; /** * Additional store's constructor params */ protected readonly storesParams: IManagerParams['storesParams']; /** * Manager options */ readonly options: IManagerOptions; /** * Suspense stores relations * @see withStores */ protected suspenseRelations: Map<string, Set<string>>; /** * Mobx manager logger */ protected readonly logger: Logger; /** * @constructor */ /** * @constructor */ constructor({ initState, storesParams, storage, options, logger }?: IManagerParams); /** * Init store manager */ /** * Init store manager */ init(): Promise<Manager>; /** * Get manager instance */ /** * Get manager instance */ static get(): Manager; /** * Get all stores */ /** * Get all stores */ getStores(): Manager['stores']; /** * Get stores relations */ /** * Get stores relations */ getStoresRelations(): Manager['storesRelations']; /** * Get suspense relations with stores */ /** * Get suspense relations with stores */ getSuspenseRelations(): Manager['suspenseRelations']; /** * Get persisted stores ids */ /** * Get persisted stores ids */ static getPersistedStoresIds(): Set<string>; /** * Push initial state dynamically * E.g. when stream html */ pushInitState: (storesState?: Record<string, any>) => void; /** * Get store identity */ /** * Get store identity */ protected getStoreId<T extends TAnyStore>(store: IConstructableStore<T> | TInitStore, params?: IStoreParams): string; /** * Get exist store */ /** * Get exist store */ getStore<T>(store: IConstructableStore<T>, params?: IStoreParams): T | undefined; /** * Lookup store */ /** * Lookup store */ protected lookupStore(id: string, params: IStoreParams): TInitStore<TAnyStore> | undefined; /** * Get bigger context from two */ /** * Get bigger context from two */ protected getBiggerContext(ctx1?: string, ctx2?: string): string | undefined; /** * Create new store instance */ /** * Create new store instance */ protected createStore<T>(store: IConstructableStore<T>, params: Omit<Required<IStoreParams>, 'key'>): T; /** * Create stores for component * * NOTE: use only inside withStores wrapper */ /** * Create stores for component * * NOTE: use only inside withStores wrapper */ createStores(map: [string, TStoreDefinition][], parentId: string, contextId: string, suspenseId: string, componentName: string, componentProps?: Record<string, any>): IGroupedStores; /** * Create empty relation context */ /** * Create empty relation context */ protected createRelationContext(contextId: string, parentId?: string, componentName?: string): void; /** * Delete relation context id */ /** * Delete relation context id */ protected removeRelationContext(contextId: string): void; /** * Prepare store before usage */ /** * Prepare store before usage */ protected prepareStore(store: TStores[string]): void; /** * Remove store */ /** * Remove store */ protected removeStore(store: TStores[string]): void; /** * Mount stores to component * * NOTE: use only inside withStores wrapper */ /** * Mount stores to component * * NOTE: use only inside withStores wrapper */ mountStores(contextId: string, { globalStores, relativeStores }: Partial<IGroupedStores>): () => void; /** * Change the stores status to touched */ /** * Change the stores status to touched */ touchedStores(stores: TStores): void; /** * Change store status */ /** * Change store status */ protected setStoreStatus(store: TStores[string], status: StoreStatus): void; /** * Get store state */ /** * Get store state */ getStoreState(store: TAnyStore, withNotExported?: boolean): Record<string, any>; /** * Get store's state */ /** * Get store's state */ toJSON(ids?: string[], isIncludeExported?: boolean): Record<string, any>; /** * Save persisted store state to provided storage */ /** * Save persisted store state to provided storage */ savePersistedStore(store: IStorePersisted): Promise<boolean>; /** * Get observable store props (fields) */ /** * Get observable store props (fields) */ static getObservableProps(store: TAnyStore, withNotExported?: boolean): Record<string, any>; /** * Persist store */ /** * Persist store */ static persistStore<TSt>(store: IConstructableStore<TSt>, id: string, options?: IPersistOptions): IConstructableStore<TSt>; } export { Manager as default };