UNPKG

synapse-storage

Version:

Набор инструментов для управления состоянием и апи-запросами

32 lines (31 loc) 2.22 kB
import type { IStorage, Selectors } from '../../core'; import type { Effect } from '../../reactive'; import { Dispatcher, Effects } from '../../reactive'; import type { Synapse, SyncSynapseModule } from './synapse.types'; import type { DependencyInput } from './types'; export interface SyncEffectsContext<TState extends Record<string, any>, TDispatcher, TSelectors> { storage: IStorage<TState>; dispatcher: TDispatcher; selectors: TSelectors; deps: ReadonlyArray<{ storage: IStorage<any>; }>; } type EffectsInput<TEffects> = TEffects | Array<TEffects | Effect> | undefined; export interface SyncSynapseConfig<TState extends Record<string, any>, TDispatcher extends Dispatcher<TState> | undefined = undefined, TSelectors extends Selectors<TState> | undefined = undefined, TEffects extends Effects<TState, NonNullable<TDispatcher>, any> | undefined = undefined> { storage: () => IStorage<TState>; dispatcher?: (storage: IStorage<TState>) => TDispatcher; selectors?: (storage: IStorage<TState>) => TSelectors; dependencies?: DependencyInput[]; dependencyTimeout?: number; externalDispatchers?: Record<string, Dispatcher<any>> | ((ctx: SyncEffectsContext<TState, TDispatcher, TSelectors>) => Record<string, Dispatcher<any>>); effects?: (ctx: SyncEffectsContext<TState, TDispatcher, TSelectors>) => EffectsInput<TEffects> | Promise<EffectsInput<TEffects>>; postConstruct?: (synapse: Synapse<TState, TDispatcher, TSelectors>) => void; } /** * Ленивый handle C-формы: конструкция main синхронна и мемоизирована (строится при первом обращении * к геттеру/`ready()`), эффекты стартуют отдельно в `ready()` после `waitForDependencies`. Расцеп даёт * синхронный `handle.selectors`/`.storage`/`.state$` — основа cross-store DI. */ export declare function createSyncSynapseModule<TState extends Record<string, any>, TDispatcher extends Dispatcher<TState> | undefined, TSelectors extends Selectors<TState> | undefined>(config: SyncSynapseConfig<TState, any, any, any>): SyncSynapseModule<TState, TDispatcher, TSelectors>; export {};