Private
Readonly
behaviorsPrivate
Readonly
behaviorsPrivate
currentPrivate
delayedPrivate
Readonly
eventPrivate
Readonly
eventPrivate
Readonly
namesPrivate
parentIn 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.
the unique identifier for event type A
the unique identifier for event type B
the event source
defaults to null
See add2TypedEventSource
the unique identifier for event type A
the unique identifier for event type B
the unique identifier for event type C
the event source
defaults to null
See add2TypedEventSource
the unique identifier for event type A
the unique identifier for event type B
the unique identifier for event type C
the unique identifier for event type D
the event source
defaults to null
See add2TypedEventSource
the unique identifier for event type A
the unique identifier for event type B
the unique identifier for event type C
the unique identifier for event type D
the unique identifier for event type E
the event source
defaults to null
See add2TypedEventSource
the unique identifier for event type A
the unique identifier for event type B
the unique identifier for event type C
the unique identifier for event type D
the unique identifier for event type E
the unique identifier for event type F
the event source
defaults to null
Private
addThis 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.).
if a state for the given identifier has already been added to this Store
the unique identifier for the derived-state behavior
the source for the behavior
the initial value or value getter (for lazy initialization) or symbol NO_VALUE
, if there is no initial value (default)
This method adds an Effect
to the Store
.
the unique identifier for the effect
the Effect
function
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!
the unique identifier for the event
the event source
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).
the unique identifier for the root-state behavior
the unique identifier for the event reducing the state
pure function that takes the previous state and the event and returns a new state
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.
if a state for the given identifier has already been added to this Store
the unique identifier for the root-state behavior
the initial value or value getter
Private
addPrivate
assertThis 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)!
This method removes all sources for a behavior and then completes the behavior for all current subscribers and removes it from the store.
the unique identifier for the behavior
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!
if targetId is a BehaviorId
and already exists in this Store
EventId
, else voidthe unique identifier for the source event or behavior
the unique identifier for the target event or behavior
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!
if targetId is a BehaviorId
and already exists in this Store
EventId
, else voidthe source observable
the unique identifier for the target event or behavior
Private
createCreate 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
).
Private
createThis 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)!
the unique identifier for the event
Optional
event: undefinedthe event of the type specified by the identifier (optional in case of void type)
Optional
event: undefinedThis 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.
the unique identifier for the behavior
Private
getPrivate
getThis 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.
the unique identifier for the effect
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).
the unique identifier for the event
Private
getGet the name linked to the given SignalId
.
If no specific name was linked (via setIdName
), the default toString()
representation will be returned.
the id you are interested in
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).
the unique identifier for the behavior or event
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.
if this method is called while already inside another lifecycleRegistrationCallback
for this Store
Private
getThe getNumberOfBehaviorSources
method returns the number of sources for the specified behavior.
Again, this is mostly for testing and debugging.
the unique identifier for the behavior
The getNumberOfEventSources
method returns the number of sources for the specified event.
Again, this is mostly for testing and debugging.
Like getEventStream
, but receiving TypedEvent<T>
instead of T
.
the unique identifier for the event
The isSubscribed
method is a convenience method for testing and debugging and should
not serve any purpose in real program logic.
the unique identifier for the behavior or event
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.)
the unique identifier for the behavior
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.
the id that should be linked to a name
the name linked to the given id
Generated using TypeDoc
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.