UNPKG

@cran/lib.vue.ref

Version:

Vue Reactivity Extensions

24 lines (23 loc) 640 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAutoReset = void 0; const vue_1 = require("vue"); /** * Always return value to a fallback after the * given delay (or on next stack) * @since 0.2.0 * @category Controller */ function useAutoReset(ref, delay, fallback = ref.value) { let timer = null; return (0, vue_1.watch)(ref, function onNext() { if (timer) { clearTimeout(timer); } timer = setTimeout(function onTimeout() { timer = null; ref.value = fallback; }, delay); }); } exports.useAutoReset = useAutoReset;