UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 1.25 kB
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-throttle-render/index.ts"],"sourcesContent":["import { onMounted, ref, watch } from 'vue'\n\nimport type { Ref } from 'vue'\nimport type { TimeoutHandle } from '@element-plus/utils/types'\n\nexport default function (loading: Ref<boolean>, throttle = 0) {\n if (throttle === 0) return loading\n const throttled = ref(false)\n let timeoutHandle: TimeoutHandle = 0\n\n const dispatchThrottling = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle)\n }\n timeoutHandle = window.setTimeout(() => {\n throttled.value = loading.value\n }, throttle)\n }\n onMounted(dispatchThrottling)\n\n watch(\n () => loading.value,\n (val) => {\n if (val) {\n dispatchThrottling()\n } else {\n throttled.value = val\n }\n }\n )\n return throttled\n}\n"],"names":[],"mappings":";;2BAKyB,SAAuB,WAAW,GAAG;AAC5D,MAAI,aAAa;AAAG,WAAO;AAC3B,QAAM,YAAY,IAAI;AACtB,MAAI,gBAA+B;AAEnC,QAAM,qBAAqB,MAAM;AAC/B,QAAI,eAAe;AACjB,mBAAa;AAAA;AAEf,oBAAgB,OAAO,WAAW,MAAM;AACtC,gBAAU,QAAQ,QAAQ;AAAA,OACzB;AAAA;AAEL,YAAU;AAEV,QACE,MAAM,QAAQ,OACd,CAAC,QAAQ;AACP,QAAI,KAAK;AACP;AAAA,WACK;AACL,gBAAU,QAAQ;AAAA;AAAA;AAIxB,SAAO;AAAA;;;;"}