import { Result } from 'ts-results'; import { SanitizedMovexClient, MovexMasterContext } from 'movex-core-util'; import type { IObservable, MovexClient, NextStateGetter, ResourceIdentifier, CheckedState, AnyAction, ToCheckedAction, ToPrivateAction, ToPublicAction, MovexReducer } from 'movex-core-util'; import { DispatchedEventPayload, DispatchPublicFn } from './dispatch'; type ObservedItem = { subscribers: Record; checkedState: CheckedState; }; /** * This is the MovexResource running on the Client */ export declare class MovexResourceObservable implements IObservable> { private clientId; rid: ResourceIdentifier; private reducer; /** * This flag informs that the resource (client) is in sync with the master. * It starts as false and it waits for at least one "sync" or "update" call. * * For now it never goes from true to false but that could be a valid use case in the future. */ private isSynchedPromiseDelegate; private $item; private pubsy; private dispatcher; private unsubscribers; constructor(clientId: MovexClient['id'], rid: ResourceIdentifier, reducer: MovexReducer, initialSubscribers?: Record, initialCheckedState?: CheckedState); /** * This is the dispatch for this Movex Resource */ dispatch(...args: Parameters>): void; dispatchPrivate(privateAction: ToPrivateAction, publicAction: ToPublicAction): void; applyMultipleActions(actions: ToPublicAction[]): ObservedItem; /** * Same as applyAction() except it fails on mismatching checksums * * @param actionOrActionTuple * @param expectedNextChecksum * @returns */ reconciliateAction(checkedAction: ToCheckedAction, masterContext: MovexMasterContext): Result, 'ChecksumMismatch'>; private getNextCheckedStateFromAction; private computeNextState; /** * Subscribe to State updates * * @param fn * @returns */ onUpdate(fn: (p: { subscribers: Record; checkedState: CheckedState; }) => void): () => void; onDispatched(fn: (event: DispatchedEventPayload, TAction>) => void): () => void; get(): ObservedItem; getCheckedState(): CheckedState; getUnwrappedState(): TState; /** * This needs to be called each time master emits an updated state. * The dispatch won't work without it being called at least once. * * @param nextStateGetter * @returns */ syncState(nextStateGetter: NextStateGetter>): void; setUnsync(): void; /** * If set to false it doesn't wait for the master state to be synced * Good for tests at least. If not for anythign else, need to rethink it. * * @param flag */ setMasterSyncing(flag: boolean): void; update(nextStateGetter: NextStateGetter>): void; private updateCheckedState; updateUnwrappedState(nextStateGetter: NextStateGetter): void; updateSubscribers(nextStateGetter: NextStateGetter['subscribers']>): void; applyStateTransformer(masterContext: MovexMasterContext): CheckedState; private applyStateTransformerToCheckedState; applyStateTransformerToCheckedStateAndUpdate(checkedState: CheckedState, masterContext: MovexMasterContext): CheckedState; destroy(): void; } export {};