import { untracked, getCommandBus } from 'vapor-chamber';
watchEffect(() => {
// without untracked(), anything the HANDLER reads becomes a dependency
// of this effect, and it re-runs on state it never mentions
untracked(() => getCommandBus().dispatch('cartSync', cart));
});
No-op when Vue is not present, so it is safe to leave in shared code.
Vue fixed the same class of bug twice in 3.6.0-rc.3 (#15203, #15204) by
suspending tracking around callbacks — this is that idea at the bus edge.
untracked — run
fnwithout its reactive reads becoming dependencies of whatever effect is currently running.A dispatch is an ACTION, not a read: nothing it touches should make the caller re-run. Every composable in this module already applies this to its own dispatches, so you only need it when calling a raw bus from inside a reactive effect: