UNPKG

@muban/muban

Version:

Writing components for server-rendered HTML

26 lines (25 loc) 1.22 kB
import { watch as vueWatch, watchEffect as vueWatchEffect } from '@vue/runtime-core'; import { getCurrentComponentInstance } from '../Component'; // eslint-disable-next-line @typescript-eslint/no-explicit-any export function watch(sources, callback, options) { const instance = getCurrentComponentInstance(); // don't even create the effect if this component is not mounted if (instance && instance.isUnmounted) { return () => undefined; } const stopHandle = vueWatch(sources, callback, options); // register stopHandle so it gets executed when the component unmounts instance === null || instance === void 0 ? void 0 : instance.disposers.push(stopHandle); return stopHandle; } export function watchEffect(effect, options) { const instance = getCurrentComponentInstance(); // don't even create the effect if this component is not mounted if (instance && instance.isUnmounted) { return () => undefined; } const stopHandle = vueWatchEffect(effect, options); // register stopHandle so it gets executed when the component unmounts instance === null || instance === void 0 ? void 0 : instance.disposers.push(stopHandle); return stopHandle; }