Cached maps (useFacetMemo) can return values before any subscription #139
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.
The choice of
useFacetMap
oruseFacetMemo
should be based on performance metrics and what is best for each use-case. So, they should share as much as possible in terms of behaviour and API.Currently, there is one small difference between then into how they handle attempts to read their values via a
get
before any subscription has started.With
useFacetMap
, because it has no internal caching, it always reads the source data when attempting to read its value through aget
, so it would be possible to get the transformed mapped value even if no subscriptions were started.However, with
useFacetMemo
because it has a cached value, it would always just return that value instead. Meaning you could get an innitialNO_VALUE
withuseFacetMemo
when you would get the actual value withuseFacetMap
.This PR fixes this inconsistency, so both hooks behave the same when trying to read their values ahead of any subscription.