UNPKG

@activejs/core

Version:

Pragmatic, Reactive State Management for JavaScript Apps

169 lines (168 loc) 6.4 kB
import { Base } from './abstract-base'; import { BoolUnit } from './bool-unit'; import { Stream } from './stream'; import { AsyncSystemBaseConfig, AsyncSystemStreamObservableProducer as StreamObservableProducer, AsyncSystemValue, UnitToValueType, Unit } from '../models'; /** * Base class for AsyncSystem. * * It can be used to create custom, {@link AsyncSystem} like Systems. * * See {@link https://docs.activejs.dev/fundamentals/systems/custom-asyncsystem} for more details. * * Just like every other ActiveJS construct: * - AsyncSystem extends {@link Base} * - Which further extends `Observable` * * @category 3. Systems */ export declare class AsyncSystemBase<QueryUnit extends Unit, DataUnit extends Unit, ErrorUnit extends Unit, Query extends UnitToValueType<QueryUnit> = UnitToValueType<QueryUnit>, Data extends UnitToValueType<DataUnit> = UnitToValueType<DataUnit>, Error extends UnitToValueType<ErrorUnit> = UnitToValueType<ErrorUnit>> extends Base<AsyncSystemValue<Query, Data, Error>> { /** * The member Unit that is intended to portray the role of `query` aspect of an async task. * @category Member Units */ readonly queryUnit: QueryUnit; /** * The member Unit that is intended to portray the role of `response` aspect of an async task. * @category Member Units */ readonly dataUnit: DataUnit; /** * The member Unit that is intended to portray the role of `error` aspect of an async task. * @category Member Units */ readonly errorUnit: ErrorUnit; /** * The member Unit that is intended to portray the role of `pending-status` of an async task. * @category Member Units */ readonly pendingUnit: BoolUnit; /** * Configured options. \ * Combination of global-options {@link GlobalAsyncSystemConfig} and the options passed on instantiation. */ readonly config: Readonly<AsyncSystemBaseConfig<Query, Data, Error>>; /** * @internal please do not use. * * It works because all our Subjects and operations are synchronous. */ private relationshipsAutoPaused; private relationshipsManuallyPaused; /** * To check whether the inter-relationships among the member Units are active or not. * * @default `true` */ get relationshipsWorking(): boolean; /** * @internal please do not use. */ private unitsEmitCountsBeforePausing; /** * Combined value of all the member Units. * * @category Access Value */ value(): AsyncSystemValue<Query, Data, Error>; constructor( /** * The member Unit that is intended to portray the role of `query` aspect of an async task. * @category Member Units */ queryUnit: QueryUnit, /** * The member Unit that is intended to portray the role of `response` aspect of an async task. * @category Member Units */ dataUnit: DataUnit, /** * The member Unit that is intended to portray the role of `error` aspect of an async task. * @category Member Units */ errorUnit: ErrorUnit, /** * The member Unit that is intended to portray the role of `pending-status` of an async task. * @category Member Units */ pendingUnit: BoolUnit, config?: AsyncSystemBaseConfig<Query, Data, Error>); /** * A helper method that creates a stream by subscribing to the Observable returned by the param `observableProducer` callback. * * Ideally the callback function creates an Observable by applying `Observable.pipe` * on the {@link queryUnit} or `queryUnit.future$` as source Observable. * * Then, after a successful data flow, dispatch the data to the {@link dataUnit}; \ * and after a failure, dispatch the error to the {@link errorUnit}, caught by using RxJS' catchError operator. * * Just know that you should catch the error in a sub-pipe (ie: do not let it propagate to the main-pipe), otherwise * as usual the stream will stop working, and will not react on any further emissions. * * @param observableProducer A callback function that should return an Observable. * * @category Common */ createStream<R>(observableProducer: StreamObservableProducer<QueryUnit, DataUnit, ErrorUnit, R>): Stream; /** * To pause inter-relationships among the member Units. Also see {@link relationshipsWorking}. * * When inter-relationships are paused, * you can perform any number of operations on the member Units * without triggering the automatic relationships like {@link AsyncSystemBaseConfig.clearErrorOnData}, * {@link AsyncSystemBaseConfig.autoUpdatePendingValue}, etc. * * This also means that the AsyncSystem stops emitting new values. * * @category Custom AsyncSystem */ pauseRelationships(): void; /** * To resume inter-relationships among the member Units. Also see {@link relationshipsWorking}. * * It restores the inter-relationships like {@link AsyncSystemBaseConfig.clearErrorOnData}, * {@link AsyncSystemBaseConfig.autoUpdatePendingValue}, etc. * * This also means that the AsyncSystem starts emitting new values. \ * And if any of the member Units emitted a value while the relationships were paused, * the AsyncSystem will emit a new value immediately to bring itself and its subscribers in sync * with the member Units. * * @category Custom AsyncSystem */ resumeRelationships(): void; /** * @internal please do not use. */ private unitsEmitCounts; /** * @internal please do not use. */ private createRelationshipsAmongMemberUnits; /** * @internal please do not use. */ private executeQueryUnitRelationship; /** * @internal please do not use. */ private executeDataUnitRelationship; /** * @internal please do not use. */ private executeErrorUnitRelationship; /** * @internal please do not use. */ private toggleQueryUnitFreezeMaybe; /** * @internal please do not use. */ private autoUpdatePendingValue; /** * @internal please do not use. */ protected emit(value?: AsyncSystemValue<Query, Data, Error>): void; /** * @internal please do not use. */ private combinedEmittedValues; }