Support options.normalizeResult
callback in wrap(fn, options)
to allow reconciling newly computed results with previous results
#283
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.
Sometimes a function cached with
optimism
will be spuriously dirtied (directly or indirectly) in a way that triggers recomputation the next time the function is called. The newly computed result may be logically different from the previous result, of course, but if the two results are equivalent (or share equivalent subparts), the developer may wish to keep using (parts of) the previous result.To take advantage of this system for reconciling cached results, pass an
options.normalizeResult
callback in the options for thewrap
function:Normally, this function would always return the
newer
array, but usingnormalizeResult
allows theoptimism
system to continue usingolder
in cases whereequal(newer, older)
, which helps limit referential diversity ofrange
arrays over time.Since this
normalizeResult
system works withinoptimism
, at each level of the dependency graph, it should be able to provide referential stability benefits similar to those promised by cache result canonization (apollographql/apollo-client#7439), without using nearly as much memory.