Skip to content
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

Rule proposal: do not use 'watch' #2415

Open
illegalnumbers opened this issue Mar 4, 2024 · 2 comments
Open

Rule proposal: do not use 'watch' #2415

illegalnumbers opened this issue Mar 4, 2024 · 2 comments

Comments

@illegalnumbers
Copy link

Please describe what the rule should do:
Prevent using the watch function without a override. This can cause very subtle race conditions throughout your application.

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<!-- ✗ BAD -->
<script>
watch(refThing, (newRefThing) => {
console.log(newRefThing)
})
</script>
<!-- ✓ GOOD -->
<script>
// eslint-disable-next-line @vue/do-not-use-watch
watch(refThing, (newRefThing) => {
console.log(newRefThing)
})
</script>
@mordae
Copy link
Contributor

mordae commented May 19, 2024

Not a maintainer, but I believe you should elaborate on said race conditions, because watch is quite fundamental to solving certain situations and the example you have provided is something that's perfectly safe to do.

@illegalnumbers
Copy link
Author

I agree that watch is fundamental for many things. Another example I can give is having a ref with 2 watches that are async and the effect is calling a different API to update that ref at different times. These two API calls have different effects and someone can use a watch without thinking of the consequences of the side effects of a slower API doing something inappropriate to a ref on the page.

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

No branches or pull requests

2 participants