-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(observer): invoke getters on initial observation if setter defined. Corrects #7302 #7828
Conversation
@pkaminski good change. @yyx990803 I think VueJS needs to think through and define properly behaviour for objects that have Example use case that was not mentioned here (I think) is that you can define properties with I'm not saying that above is an argument that we should define reactive logic for above use case. I'm just adding this example as an addition to the discussion and I'm saying that this problem should be analysed more, so proper logic can be defined - not necessarily making above use case work. Evan I know that you are super busy, so when I work more with my use case I may come back here and add some more input from the analysis point of view. |
I will just dump some ideas here when they come. First finding
Line One would argue why would anybody run Let's again use validator example (very simplified for readability):
Above logic can be easily extended into tracking validation errors, custom number of fields with custom validators, displaying of errors automatically and disabling submit button on validation errors etc. Besides this example I think that object's whole behaviour, even in stupid use cases, should not be modified or broken. |
Run setter logic for nested setters even if value didn't change. See this: vuejs#7828 (comment). BREAKING CHANGE: Run setter logic for nested setters even if value didn't change.
Run setter logic for nested setters even if value didn't change. See this: vuejs#7828 (comment). BREAKING CHANGE: Run setter logic for nested setters even if value didn't change.
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
After #7302, there's an asymmetry in
defineReactive
for properties that have both a getter and a setter. On initial creation, the value returned by the getter is not made reactive since #7302 makes sure not to fetch it andobserve(val)
is a no-op. However, if the value is set again after the property has been made reactive, it is made reactive as well sinceobserve(newVal)
inset
is not gated on missing a getter. (The premise justifying the change in #7280 that "why should we get the value of the property in walk, despite the fact, that it is used only if the property has no getter" is wrong, as the value was used in the call toobserve
even if the property had a getter.)With the present change, properties that only have a getter will still not have their value fetched and won't be made reactive, which should continue to satisfy @DeyLak's needs IIUC. However, properties that have both a getter and a setter will continue to behave like they did before, being made recursively reactive, and their initial value treated consistently with subsequently set ones.
If you think that treating getter vs getter/setter properties differently is confusing, then you may want to revert #7302 instead so all values are made recursively reactive, irrespective of how the property is defined. This may be easier for developers to understand but would break @DeyLak's use case.