You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
computed internally uses Object.is to compare whether the old and new values have changed. This is valid for primitives, but cannot compare objects (this is the correct behavior).
We can expose the computed last value for getter, so the user can decide whether to return the last value for object to pass Object.is.
Another alternative is to provide isEqual option, but I don't recommend this approach. This requires always fully executing the getter and returning a new object, which I think limits performance and GC pitfalls that the user should be able to avoid.
getter cannot exit early on equal to avoid possible expensive operations
getter may be executed frequently and return object to execute isEqual that needs to GC
How much does redundant re-rendering affect performance compared to doing a (sometimes really heavy) isEquals-like check? Maybe it's wise to do some benchmarks to see if this API change truly improves performance in various scenarios. E.g.:
Small vs. huge objects/arrays/Map/Set/etcetera.
Small vs. big templates.
I don't think it's wise to provide an isEqual option, however, it may be wise to read some good docs on what kind of techniques truly improve performance and which ones don't. Also, the docs need to be really clear about only using this as an opt-in performance enhancement for non-primitives. Maybe some ESLint rules would also be nice, one for requiring usage of the oldValue parameter on every computed that returns a non-primitive, and one for warning about usage of oldValue on primitives.
I have some concerns about this addition. Given this PR has already been merged into minor, I've started a separate discussion at vuejs/rfcs#594, rather than posting it all here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
computedinternally usesObject.isto compare whether the old and new values have changed. This is valid for primitives, but cannot compare objects (this is the correct behavior).We can expose the
computedlast value for getter, so the user can decide whether to return the last value for object to passObject.is.Another alternative is to provide
isEqualoption, but I don't recommend this approach. This requires always fully executing the getter and returning a new object, which I think limits performance and GC pitfalls that the user should be able to avoid.isEqualthat needs to GC