Skip to content

Set default lazy option to true in watch api #304

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

Closed
wants to merge 1 commit into from

Conversation

takumi-n
Copy link

@takumi-n takumi-n commented Apr 6, 2020

This pull request fixes that watch function runs when a source variable has been defined.

https://vue-composition-api-rfc.netlify.com/api.html#watch

The watch API is the exact equivalent of the 2.x this.$watch (and the corresponding watch option). watch requires watching a specific data source, and applies side effects in a separate callback function. It also is lazy by default - i.e. the callback is only called when the watched source has changed.

As stated in Vue Composition API documents, the callback function passed to watch should run only when the source has changed.

vuejs/composition-api always sets lazy field of WatcherOption to false by default,
https://github.com/vuejs/composition-api/blob/master/src/apis/watch.ts#L60

but it should be true in watch

Resolve #266

@takumi-n takumi-n force-pushed the fix/watch-default-lazy branch from 233e297 to d6487a8 Compare April 6, 2020 11:50
@takumi-n takumi-n force-pushed the fix/watch-default-lazy branch from d6487a8 to 523ca1c Compare April 6, 2020 12:02
@antfu
Copy link
Member

antfu commented Apr 6, 2020

Hi, I think the lazy option is replaced by immediate and default to false. I have already made PR #300 addressing that.

@takumi-n
Copy link
Author

takumi-n commented Apr 7, 2020

@antfu
Hi, I have overlooked your PR.
I think that vuejs/composition-api keeps lazy for two reasons.

  1. As you have said, switching from lazy to immediate breaks compatibility.
  2. vuejs/composition-api could differ from RFC and Vue.js 3 because lazy is stated in RFC

@jacekkarczmarczyk
Copy link
Contributor

@takumi-n
Copy link
Author

takumi-n commented Apr 7, 2020

@jacekkarczmarczyk
Thanks. I didn't know that at all.

I think #300 is better.

@takumi-n takumi-n closed this Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjust watch behaviour to match latest RFC update
3 participants