The rx-signals Store provides RxJs-Observables for RP (reactive programming) - BehaviorStreams and EventStreams (behaviors and events are the two different types of signals, where behaviors represent immutable state). The Store separates the sources of these streams from the streams itself.

Hierarchy

  • Store

Constructors

Properties

behaviors: Map<symbol, ControlledSubject<any>> = ...
behaviorsSubject: BehaviorSubject<Map<symbol, ControlledSubject<any>>> = ...
currentLifecycleObjects: null | {
    behaviors: symbol[];
    events: symbol[];
} = null
delayedEventQueue: DelayedEventQueue = ...
eventStreams: Map<symbol, ControlledSubject<any>> = ...
eventStreamsSubject: BehaviorSubject<Map<symbol, ControlledSubject<any>>> = ...
names: Map<symbol, string> = ...
parentStore: null | Store = null

Methods

  • In contrast to addEventSource, this method adds an event source to the Store that can dispatch two different event types A and B. If you set the optional parameter subscribeObservableOnlyIfEventIsSubscribed, the whole source will only be subscribed, if the event corresponding to this parameter is subscribed. A common use-case for this would be an effect that dispatches A as result and B as generic error event. If you have a central error handler listening to B, this would normally always subscribe the whole effect (you will listen for errors over the whole lifetime of your app), hence it would make lazy subscription of A impossible. But if you set subscribeObservableOnlyIfEventIsSubscribed to eventIdentifierA, then the whole source will ONLY be subscribed as long as A is subscribed.

    Returns

    • a symbol that can be used to remove the event-source from the store

    Type Parameters

    Parameters

    Returns symbol

  • This adds an observable representing derived state, hence state that depends on other behaviors, to the store. The store will not eagerly subscribe the given observable. While derived state usually depends on other Behaviors and not on events, there are still valid use-cases where the given observable might depend on an event. E.g., if you want to transform an event-stream into a lazily-subscribed behavior (However, the more idiomatic way to do this would be to use the connect method instead.).

    Throws

    if a state for the given identifier has already been added to this Store

    Returns

    Type Parameters

    Parameters

    • identifier: ID

      the unique identifier for the derived-state behavior

    • observable: Observable<ToBehaviorIdValueType<ID>>

      the source for the behavior

    • initialValueOrValueGetter: "$RX-SIGNALS-NO-VALUE$" | ToBehaviorIdValueType<ID> | (() => ToBehaviorIdValueType<ID>) = NO_VALUE

      the initial value or value getter (for lazy initialization) or symbol NO_VALUE, if there is no initial value (default)

    Returns void

  • This method adds an Effect to the Store.

    Returns

    Type Parameters

    Parameters

    • id: ID

      the unique identifier for the effect

    • effect: ToEffectType<ID>

      the Effect function

    Returns void

  • This method adds an event source to the store. There can be multiple sources for the same event type. However, each source must be identified by its own symbol and adding two sources with the same symbol would result in an error. Event sources are effects!

    Returns

    • a symbol that can be used to remove the event-source from the store

    Type Parameters

    Parameters

    • eventIdentifier: ID

      the unique identifier for the event

    • observable: Observable<ToEventIdValueType<ID>>

      the event source

    Returns symbol

  • This adds a reducer to a behavior. This is meant to be used together with the addState method. The corresponding event will be subscribed eagerly by the store. If the event comes from an event-source that should be lazy, this situation can be solved using one of the addXTypedEventSource methods (see corresponding documentation) for this event-source (another solution would be to switchMap the event-source depending on whatever condition).

    Returns

    Type Parameters

    Parameters

    • stateIdentifier: SID

      the unique identifier for the root-state behavior

    • eventIdentifier: EID

      the unique identifier for the event reducing the state

    • reducer: StateReducer<ToBehaviorIdValueType<SID>, ToEventIdValueType<EID>>

      pure function that takes the previous state and the event and returns a new state

    Returns void

  • This method adds a source for the state specified by the given identifier, that provides the given value as initial value for the corresponding behavior. It will be the only value, as long as no reducer is added. Use this for root-state only, hence state that only depends on events, but not on any other behavior. The store will eagerly subscribe all reducers being added for the state. If one of those reducers depends on an event-source that should be lazy, this situation can be solved using one of the addXTypedEventSource methods (see corresponding documentation) for the corresponding event-source.

    Throws

    if a state for the given identifier has already been added to this Store

    Returns

    Type Parameters

    Parameters

    Returns void

  • Type Parameters

    • T

    Parameters

    • sourceIdentifier: symbol
    • eventIdentifier: EventId<T>
    • sharedSource: Observable<Readonly<{
          event: T;
          type: EventId<T>;
      }>>

    Returns void

  • Parameters

    • symbol: symbol
    • sourceIdentifier: symbol

    Returns void

  • This method removes all sources for all behaviors and all event streams and then completes them for all current subscribers and removes them from the store. This method should be used to end a stores lifetime (e.g. for a child store), to make sure no non-lazy subscriptions keep the store alife (hence avoiding memory leaks)!

    Returns

    Returns void

  • This method removes all sources for a behavior and then completes the behavior for all current subscribers and removes it from the store.

    Returns

    Type Parameters

    • T

    Parameters

    • identifier: BehaviorId<T>

      the unique identifier for the behavior

    Returns void

  • The connect method takes a source- and a target-ID and adds a corresponding source for the targetId to the store, connecting the source event or behavior with the target event or behavior. Thus, if targetId is a BehaviorId, a source must not yet exist in the store, else this method will throw a corresponding error!

    Throws

    if targetId is a BehaviorId and already exists in this Store

    Returns

    • symbol of the added event source in case the targetId is an EventId, else void

    Type Parameters

    • TID extends SignalId<any>

    • S extends any

    Parameters

    • sourceId: SignalId<S>

      the unique identifier for the source event or behavior

    • targetId: TID

      the unique identifier for the target event or behavior

    Returns TID extends BehaviorId<ToSignalIdValueType<TID>> ? void : symbol

  • This connects the source observable with the target event or behavior. If the targetId is a BehaviorId, a corresponding behavior source will be added to the store. If the targetId is an EventId, a corresponding event-source will be added to the store. Hence, if targetId is a BehaviorId, it must not yet exist in the store, else this method will throw a corresponding error!

    Throws

    if targetId is a BehaviorId and already exists in this Store

    Returns

    • symbol of the added event source in case the targetId is an EventId, else void

    Type Parameters

    • TID extends SignalId<any>

    • S extends any

    Parameters

    • source: Observable<S>

      the source observable

    • targetId: TID

      the unique identifier for the target event or behavior

    Returns TID extends BehaviorId<ToSignalIdValueType<TID>> ? void : symbol

  • Type Parameters

    • T

    Parameters

    Returns ControlledSubject<T>

  • Create and return a child store of this store. Event-subscribers of the child store will receive events from the parent (and its parents) and their own events (see getEventStream). However, events dispatched on the child will not propagate to the parent. The child will use the same event queue as the parent to ensure correct event order even between parent-child boundaries. Behavior-subscribers of the child will receive the observable from the parent, as long as no corresponding behavior source is added to the child. It will switch to the child, once a source is added there (see getBehavior).

    Returns

    Returns Store

  • Type Parameters

    • T

    Parameters

    Returns ControlledSubject<T>

  • This method is used to dispatch an event of the type specified by the given identifier. The only reason for returning a promise instead of directly returning a boolean is to simplify testing (e.g. make sure a dispatch is finished before checking the new state). In real code, awaiting the returned promise would be a severe code smell (dispatching an event is an effect and the only way to know an effect has been finished is to receive a corresponding message, either in form of another event, or in form of a corresponding new state)!

    Returns

    • a promise that resolves to true, if the event was subscribed, else to false

    Parameters

    • identifier: EventId<undefined>

      the unique identifier for the event

    • Optional event: undefined

      the event of the type specified by the identifier (optional in case of void type)

    Returns Promise<boolean>

  • Parameters

    • identifier: EventId<void>
    • Optional event: undefined

    Returns Promise<boolean>

  • Type Parameters

    Parameters

    Returns Promise<boolean>

  • This method returns the behavior specified by identifier. It does not matter, if a source for the behavior has already been added or not. If a source has already been added, a subscriber will get the latest value from the source. Else, a subscriber will get the initial value, as soon as a source is added. Please note, that all behaviors are shared and distinct value streams (hence you do not have to pipe with distinctUntilChanged and shareReplay yourself). The sharing behaves like shareReplay(1), but WITHOUT the risk of a memory leak that would be possible with shareReplay(1). If this store has a parent store, then as long as no behavior source is added for the child, the behavior will be received from the parent. As soon, as a corresponding source is added to the child, you will receive the behavior values from the child.

    Returns

    • the behavior observable (shared and distinct)

    Type Parameters

    • T

    Parameters

    • identifier: BehaviorId<T>

      the unique identifier for the behavior

    Returns Observable<T>

  • Type Parameters

    • T

    Parameters

    Returns ControlledSubject<T>

  • Type Parameters

    • T

    Parameters

    • observable: Observable<T>
    • subscribeObservableOnlyIfEventIsSubscribed: null | EventId<any>

    Returns Observable<T>

  • This method returns an Observable for the effect specified by identifier. It does not matter, if the effect has already been added or not. If it has already been added, a subscriber will get it immediately. Else, a subscriber will get the effect as soon as it is added to the store. If this store has a parent store, then as long as no effect is added for the child, the effect will be received from the parent. As soon, as a corresponding effect is added to the child, subscribers will receive the effect from the child.

    Returns

    • the effect observable

    Type Parameters

    • InputType

    • ResultType

    • ErrorType

    Parameters

    • id: EffectId<InputType, ResultType, ErrorType>

      the unique identifier for the effect

    Returns Observable<Effect<InputType, ResultType, ErrorType>>

  • This method returns an observable for events of the specified type. Please note, that all observables for the same identifier are already piped with delay(1, asyncScheduler) and share(). So events will always be received asynchronously (expecting synchronous event dispatch would be a strong indicator of flawed design, because it could break reactivity). If this store has a parent store, events from both, parent and child will be observed (merged).

    Returns

    • the behavior observable for the events (piped with delay(1, asyncScheduler) and share())

    Type Parameters

    • T

    Parameters

    • identifier: EventId<T>

      the unique identifier for the event

    Returns Observable<T>

  • Type Parameters

    • T

    Parameters

    Returns ControlledSubject<T>

  • Get the name linked to the given SignalId. If no specific name was linked (via setIdName), the default toString() representation will be returned.

    Returns

    • the name linked to the id, or the corresponding toString() result

    Type Parameters

    • T

    Parameters

    • id: SignalId<T>

      the id you are interested in

    Returns string

  • The getIsSubscribedObservable method is the reactive counterpart for the isSubscribed method, also serving mainly for testing and debugging purposes (though in contrast to the non-reactive counterpart, you could actually use this in some scenarios, but there are likely more idiomatic ways).

    Returns

    • upon subscription, lets you keep track whether the corresponding event or behavior is subscribed

    Type Parameters

    • T

    Parameters

    • identifier: SignalId<T>

      the unique identifier for the behavior or event

    Returns Observable<boolean>

  • This method takes a callback that performs Store operations. It returns a LifecycleHandle that can be used to reset or end the lifecycle of signals and signal-sources that are added to the store during the callback execution.

    Throws

    if this method is called while already inside another lifecycleRegistrationCallback for this Store

    Returns

    Parameters

    • lifecycleRegistrationCallback: ((store: Store) => void)

      behaviors and event-sources added within this callback will be part of the lifecycle

        • (store: Store): void
        • Parameters

          Returns void

    Returns LifecycleHandle

  • Parameters

    • id: symbol

    Returns string

  • The getNumberOfBehaviorSources method returns the number of sources for the specified behavior. Again, this is mostly for testing and debugging.

    Returns

    • the current number of sources for the specified behavior

    Type Parameters

    • T

    Parameters

    • identifier: BehaviorId<T>

      the unique identifier for the behavior

    Returns number

  • The getNumberOfEventSources method returns the number of sources for the specified event. Again, this is mostly for testing and debugging.

    Returns

    • the current number of sources for the specified event

    Type Parameters

    • T

    Parameters

    Returns number

  • Get the parent store of this store, or null in case it has no parent store.

    Returns

    Returns null | Store

  • Get the root store of this store, in case this store is a child store in a hierarchy of parent-child stores. Returns itself, if this store has no parent.

    Returns

    Returns Store

  • Like getEventStream, but receiving TypedEvent<T> instead of T.

    Returns

    • the observable for the typed events

    Type Parameters

    • T

    Parameters

    • identifier: EventId<T>

      the unique identifier for the event

    Returns Observable<Readonly<{
        event: T;
        type: EventId<T>;
    }>>

  • The isSubscribed method is a convenience method for testing and debugging and should not serve any purpose in real program logic.

    Returns

    • true, if the corresponding event or behavior is currently subscribed

    Type Parameters

    • T

    Parameters

    • identifier: SignalId<T>

      the unique identifier for the behavior or event

    Returns boolean

  • This method removes all sources for a behavior. (Yes, from the API-point-of-view, there can be only one source for a behavior. However, technically each reducer added for a root-state-behavior also represents a source.)

    Returns

    Type Parameters

    • T

    Parameters

    • identifier: BehaviorId<T>

      the unique identifier for the behavior

    Returns void

  • This method removes the specified event source.

    Returns

    Parameters

    • sourceIdentifier: symbol

      the unique identifier for the event source

    Returns void

  • This method can be used to remove a reducer from a root-state behavior.

    Returns

    Type Parameters

    • T

    • E

    Parameters

    • stateIdentifier: StateId<T>

      the unique identifier for the root-state behavior

    • eventIdentifier: EventId<E>

      the unique identifier for the event the reducer is handling

    Returns void

  • This method resets all behaviors, effectively resetting the complete store to the state it had before any event was dispatched. Technically, this is done by first removing all sources and then adding them again.

    Returns void

  • This method can be used to link a SignalId with a name. The corresponding name will then be used in future debug methods to represent tracked signals.

    Returns

    Type Parameters

    • T

    Parameters

    • id: SignalId<T>

      the id that should be linked to a name

    • name: string

      the name linked to the given id

    Returns void

Generated using TypeDoc