Expose effect in bundle / allow passing an instance to watch/watchEffect
What problem does this feature solve?
It is not possible to create a watcher that is not influenced by lifecycle hooks of a component if it is created in the setup function.
The doWatch
method allows passing an instance which would allow passing null
and therefore disable lifecycle tracking for the watcher. However, watch/watchEffect
doesn't have this parameter.
Another possibility would be to create a low-level effect
. However, it is not exposed to the Vue
-Object when using the browser bundle.
So either exposing effect
or allow to pass an instance to watch/watchEffect
would solve this issue.
What does the proposed API look like?
Vue.watch(getter, cb, options, instance)
Vue.watchEffect(cb, options, instance)
const effect = Vue.effect
There's an RFC being discussed to allow for a broader solution, i.e. for computeds:
https://github.com/vuejs/rfcs/pull/212
Please give feedback there.