A valid instance of type STORE_TYPE
, serving as the initial value of the data.
Updates the ObservableStore based on the current values in the store. This is useful if you need functionality
such as "add an item to an existing array in the store". (Remember that the store values should generally be
immutable, so in this example, you should .concat
rather than .push
).
A function which takes the current data of the store and returns an object with a subset
(Pick
) of the fields.
The calculated fields will be updated in the store, and any Observables
will be triggered as if the values had
been set with set.
The result of the update function; i.e. the same object which has been set in the store.
Updates the ObservableStore asynchronously based on the current values in the store. This is useful if you need functionality
such as "add an item to an existing array in the store". (Remember that the store values should generally be
immutable, so in this example, you should .concat
rather than .push
).
A function which takes the current data of the store and returns a Promise
of a subset
(Pick
) of the fields.
Once the Promise
fulfills, the calculated fields will be updated in the store, and any Observables
will
be triggered as if the values had been set with set.
The result of the update function; i.e. the same Promise
d object which will be set in the store.
Returns the current value of the internal data. This is a shallow copy, and should not be used to manipulate the fields of the store.
Returns an Observable
which emits the values for the given key as they are updated.
This is essentially a shorthand for
observableStore.pipe(
map(data => data.key),
distinctUntilChanged((a, b) => deepEqual(a, b))
);
Returns an Observable
of an object consisting of the specified fields.
This is essentially a shorthand for
observableStore.pipe(
map(data => ({
k1: data.k1,
k2: data.k2
})),
distinctUntilChanged((a, b) => deepEqual(a, b))
);
Returns an Observable
of an object consisting of the specified fields.
This is equivalent to
observableStore.pipe(
map(data => ({
k1: data.k1,
k2: data.k2
})),
distinctUntilChanged((a, b) => deepEqual(a, b))
);
Sets a given field to a given value. If the new value is not equal to the current value, it will trigger a
notification in the relevant Observable
s. (See observe)
The name of the field. Must be a field in type T
The new value. Must be of the appropriate type.
Sets several fields at once. If any of the new values are not equal to the current value, it will trigger a
notification in the relevant Observable
s. (See observe)
An object containing key/value pairs to set. The object must be a subset (Pick
) of type T
An
ObservableStore
maintains data of generic typeSTORE_TYPE
, providing methods to set the fields, in turn emitting values on requestedObservable
s. TheObservableStore
is itself anObservable
of typeSTORE_TYPE
, acting like aBehaviorSubject
, maintaining a single value and replaying it to new subscribers.