Files
lan-manager/web/node_modules/element-plus/es/hooks/use-throttle-render/index.mjs
openclaw 0a5f6a8047 Initial commit: Lan-manager project code
- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs

Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
2026-04-20 00:52:58 +08:00

34 lines
1.1 KiB
JavaScript

import { isNumber, isObject, isUndefined } from "../../utils/types.mjs";
import { onMounted, ref, watch } from "vue";
//#region ../../packages/hooks/use-throttle-render/index.ts
const useThrottleRender = (loading, throttle = 0) => {
if (throttle === 0) return loading;
const throttled = ref(isObject(throttle) && Boolean(throttle.initVal));
let timeoutHandle = null;
const dispatchThrottling = (timer) => {
if (isUndefined(timer)) {
throttled.value = loading.value;
return;
}
if (timeoutHandle) clearTimeout(timeoutHandle);
timeoutHandle = setTimeout(() => {
throttled.value = loading.value;
}, timer);
};
const dispatcher = (type) => {
if (type === "leading") if (isNumber(throttle)) dispatchThrottling(throttle);
else dispatchThrottling(throttle.leading);
else if (isObject(throttle)) dispatchThrottling(throttle.trailing);
else throttled.value = false;
};
onMounted(() => dispatcher("leading"));
watch(() => loading.value, (val) => {
dispatcher(val ? "leading" : "trailing");
});
return throttled;
};
//#endregion
export { useThrottleRender };
//# sourceMappingURL=index.mjs.map