element-plus
Version:
> TODO: description
29 lines (28 loc) • 780 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vue_1 = require("vue");
function default_1(loading, throttle = 0) {
if (throttle === 0)
return loading;
const throttled = vue_1.ref(false);
let timeoutHandle = 0;
const dispatchThrottling = () => {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
timeoutHandle = window.setTimeout(() => {
throttled.value = loading.value;
}, throttle);
};
vue_1.onMounted(dispatchThrottling);
vue_1.watch(() => loading.value, val => {
if (val) {
dispatchThrottling();
}
else {
throttled.value = val;
}
});
return throttled;
}
exports.default = default_1;