-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
watch
behavior in v3 is different to v2
#671
Comments
Yes, these are somewhat intended.
I think an RFC would be great to gather more feedback on these changes. |
Re: your first point: while it makes sense that having different APIs for watchers between Composition and Object API might be confusing, in my personal experience, I use |
@lbogdan I think there is a force of habit here. What I've found is that in a lot of cases people are actually doing this: created() {
this.fetchData(this.id)
},
watch: {
id: fetchData
},
methods: {
fetchData(id) {
// ...
}
} Where with immediate by default this becomes: watch: {
id(id) {
// fetch data...
}
} Would be great to learn more about cases where |
Yes, that's exactly the use-case I use |
@lbogdan yeah, that would be really helpful. |
Want to chime in that currently I often rely on watchers not being triggered immediately because I put client-only code in them when I know that a change wont ever happen on the server (eg because a change can only happen after user interaction). |
I opened an RFC as suggested; I'll close this so we can keep discussion in one place. |
@pimlie FYI |
I do it myself all the time. But it's not out of habit, it's about how you think about the watcher. When I make an algorithm in my head I think something like this:
And the fact that an watcher can launch a handler right at the moment of installation is a little confusing. I want to say that this is how you perceive the logic of work by its name. Perhaps if this api was called otherwise, say |
@cawa-93 that's a good point. So another option we have is:
|
@yyx990803 I too think that's a much better compromise. In regard to naming:
L.E. Nvm, I misunderstood adding a new option to the options API vs. renaming |
@lbogdan I've always disliked But Im not a native speaker, so maybe thats just me. |
I'm not a fan of |
I also think that |
My reasoning for |
Please use the RFC for further discussions so that we can have it all in one place, thanks! |
Version alpha 4
Reproduction link
https://codesandbox.io/s/v-model-decomposed-camel-case-lx173
Steps to reproduce
Take this simple app. In Vue.js 2, it will not do the
console.log
, unless you setimmediate: true
in watch options.In Vue.js 3, however,
watch
triggers immediately by default. That is because the default for thewatch
hook is{ lazy: true }
as discussed here under "Lazy Invocation". This means in the current state, this would be a breaking change for Vue.js 2 apps relying on theimmediate
option defaulting tofalse
.Also, in Vue 2.x you can do:
And watch a deeply nested property. This appears to not work in Vue 3.X - nothing happens.
What is expected?
Behavior same as Vue 2.X, or open RFC to change behavior:
What is actually happening?
I like the new changes, they rock. Just need to make sure we have either a clear migration path for people relying on old behavior if making changes.
I am happy to make a PR making changes to the code base if needed, or an RFC regarding the breaking changes.
The text was updated successfully, but these errors were encountered: