feat: Async store and compute()
function
#14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Async store
This is a new implementation of the store. The previous one was based on
BehaviourSubject
which emitted synchronous notifications for state updates.The new store is based on its own subscription collection and schedules a notification of subscribers on the next micro task. Also subscribers receive only on notification with a current state. All subsequent events are dropped because they don't matter.
Behaviour of a subscription is the same: a new subscriber receives a current state on subscribing synchronously.
Subscribers can receive a current state synchronously at any time by invoking
store.notify()
manually.compute()
This function creates a computable query which calculates its values by provided "computation" function and dependencies.
Rules of "Computation" function:
"Computation" function provides a resolver for using a dependency withing a calculation expression.
Dependency can be declared explicitly as an array by the second argument. It has the following advantages:
A custom value comparator can be specified by "options" object as the second argument.
It helps to decide if a new value differs from a previous one in complex cases.
Example
Perfomance