Skip to content

Support stopping a watcher by calling it - #148

Merged
berendkleinhaneveld merged 3 commits into
masterfrom
support-disabling-watchers
Dec 16, 2025
Merged

Support stopping a watcher by calling it#148
berendkleinhaneveld merged 3 commits into
masterfrom
support-disabling-watchers

Conversation

@berendkleinhaneveld

Copy link
Copy Markdown
Collaborator

This can help with disabling watchers at critical moments, for example right before they are removed. This alleviates the need for work-arounds such as installing a dummy fn property and clearing the callback property.

This can help with disabling watchers at critical moments, for
example right before they are removed. This alleviates the need
for work-arounds such as installing a dummy fn property and
clearing the callback property.
@Korijn

Korijn commented Dec 15, 2025

Copy link
Copy Markdown
Collaborator

Vue also has this kind of option right?

@berendkleinhaneveld

Copy link
Copy Markdown
Collaborator Author

Kind of: you can stop it with returned value: https://vuejs.org/guide/essentials/watchers.html#stopping-a-watcher
Instead, we return the watcher itself of course, so that the caller can manage its lifetime. But yeah, there is indeed something to make it stop explicitly if really needed

@berendkleinhaneveld

Copy link
Copy Markdown
Collaborator Author

I could rename it 'stop' and make it a method instead that also unsets the callback and fn, so that resources could be released asap? That would make it more explicit and clear that the watcher has become useless after calling it.

@Korijn

Korijn commented Dec 15, 2025

Copy link
Copy Markdown
Collaborator

If it still works for you I would prefer to align with vue's design when possible, otherwise feel free to diverge

@berendkleinhaneveld

Copy link
Copy Markdown
Collaborator Author

I've now made it as in Vue, so you can call the watcher to stop it and clean up any resources.

@berendkleinhaneveld berendkleinhaneveld changed the title Add active property to Watcher Support stopping a watcher by calling it Dec 16, 2025
@Korijn

Korijn commented Dec 16, 2025

Copy link
Copy Markdown
Collaborator

Looks great!

@berendkleinhaneveld
berendkleinhaneveld merged commit cbe4ebc into master Dec 16, 2025
10 checks passed
@berendkleinhaneveld
berendkleinhaneveld deleted the support-disabling-watchers branch December 16, 2025 09:15
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.

2 participants