UNPKG

quasar

Version:

Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time

44 lines (35 loc) 759 B
import { nextTick, onDeactivated, onBeforeUnmount, getCurrentInstance } from 'vue' import { vmIsDestroyed } from '../../utils/private.vm/vm.js' /* * Usage: * registerTick(fn) * removeTick() */ export default function useTick() { let tickFn const vm = getCurrentInstance() function removeTick() { tickFn = void 0 } onDeactivated(removeTick) onBeforeUnmount(removeTick) return { removeTick, registerTick(fn) { tickFn = fn nextTick(() => { if (tickFn === fn) { // we also check if VM is destroyed, since if it // got to trigger one nextTick() we cannot stop it if (vmIsDestroyed(vm) === false) tickFn() tickFn = void 0 } }) } } }