@coreui/vue-pro
Version:
UI Components Library for Vue.js
26 lines (22 loc) • 847 B
JavaScript
;
var vue = require('vue');
const useDebouncedCallback = (callback, delay) => {
const timeout = vue.ref();
const debouncedFn = (...args) => {
const handler = () => {
clearTimeout(timeout.value);
callback(...args);
};
clearTimeout(timeout.value);
timeout.value = setTimeout(handler, delay);
};
// Mirror VueUse's tryOnScopeDispose: register the cleanup only when called
// inside an active effect scope (a component setup). Calling it outside one
// is then a no-op instead of emitting a "no active effect scope" warning.
if (vue.getCurrentScope()) {
vue.onScopeDispose(() => clearTimeout(timeout.value));
}
return debouncedFn;
};
exports.useDebouncedCallback = useDebouncedCallback;
//# sourceMappingURL=useDebouncedCallback.js.map