Skip to content

Immediate watchers with the Composition API #2144

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

Merged
merged 4 commits into from
Jan 8, 2023

Conversation

skirtles-code
Copy link
Contributor

PR #2069 attempted to introduce a section in the watcher docs about using immediate: true with the Composition API. The new additions were fine, but they posed a problem. The existing section about watchEffect() is built on the premise that it is the way to create an eager watcher. This no longer made sense when it followed a section about immediate: true.

This PR includes the original 2 commits from #2069, adding docs for immediate: true. These are closely based on the existing section about immediate: true with the Options API.

In addition, I've reworked the section about watchEffect() to avoid presenting it as just a form of eager watcher. I've changed the main example in that section to something a bit more realistic, though it is still similar to the old example. Most importantly, the previous example wasn't using immediate: true, which doesn't really make sense if we've just introduced immediate: true in the previous section. I've also tried to explain the benefits of watchEffect() a bit more explicitly, as I don't think it's obvious just from looking at the example.

@netlify
Copy link

netlify bot commented Jan 3, 2023

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 74ed547
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/63b4ade930673d0009a04e33
😎 Deploy Preview https://deploy-preview-2144--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.


```js
watch(source, (newValue, oldValue) => {
// ...
Copy link
Member

@yyx990803 yyx990803 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a bit of descriptive comment here, e.g. executed immediately, then again when source changes...

Otherwise LGTM

@NataliaTepluhina NataliaTepluhina merged commit 5e44eeb into vuejs:main Jan 8, 2023
Abdelaziz18003 referenced this pull request in vuejs-translations/docs-ar Jan 11, 2023
* Update: watchers.md

Add `Eager Watchers` section to composition side

* docs: returns consideration

* Reword the section on watchEffect

Co-authored-by: Johnny Charcosset <[email protected]>
Co-authored-by: Johnny Charcosset <[email protected]>
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.

4 participants