You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
4.2 KiB
1 lines
4.2 KiB
{"ast":null,"code":"import { ref, onMounted, watch } from 'vue';\nimport { isNumber, isUndefined } from '../../utils/types.mjs';\nimport { isObject } from '@vue/shared';\nconst useThrottleRender = (loading, throttle = 0) => {\n if (throttle === 0) return loading;\n const initVal = isObject(throttle) && Boolean(throttle.initVal);\n const throttled = ref(initVal);\n let timeoutHandle = null;\n const dispatchThrottling = timer => {\n if (isUndefined(timer)) {\n throttled.value = loading.value;\n return;\n }\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n timeoutHandle = setTimeout(() => {\n throttled.value = loading.value;\n }, timer);\n };\n const dispatcher = type => {\n if (type === \"leading\") {\n if (isNumber(throttle)) {\n dispatchThrottling(throttle);\n } else {\n dispatchThrottling(throttle.leading);\n }\n } else {\n if (isObject(throttle)) {\n dispatchThrottling(throttle.trailing);\n } else {\n throttled.value = false;\n }\n }\n };\n onMounted(() => dispatcher(\"leading\"));\n watch(() => loading.value, val => {\n dispatcher(val ? \"leading\" : \"trailing\");\n });\n return throttled;\n};\nexport { useThrottleRender };","map":{"version":3,"names":["useThrottleRender","loading","throttle","initVal","isObject","Boolean","throttled","ref","timeoutHandle","dispatchThrottling","timer","isUndefined","value","clearTimeout","setTimeout","dispatcher","type","isNumber","leading","trailing","onMounted","watch","val"],"sources":["../../../../../packages/hooks/use-throttle-render/index.ts"],"sourcesContent":["import { onMounted, ref, watch } from 'vue'\nimport { isNumber, isObject, isUndefined } from '@element-plus/utils'\n\nimport type { Ref } from 'vue'\n\nexport type ThrottleType =\n | { leading?: number; trailing?: number; initVal?: boolean }\n | number\n\nexport const useThrottleRender = (\n loading: Ref<boolean>,\n throttle: ThrottleType = 0\n) => {\n if (throttle === 0) return loading\n const initVal = isObject(throttle) && Boolean(throttle.initVal)\n const throttled = ref(initVal)\n let timeoutHandle: ReturnType<typeof setTimeout> | null = null\n\n const dispatchThrottling = (timer: number | undefined) => {\n if (isUndefined(timer)) {\n throttled.value = loading.value\n return\n }\n if (timeoutHandle) {\n clearTimeout(timeoutHandle)\n }\n timeoutHandle = setTimeout(() => {\n throttled.value = loading.value\n }, timer)\n }\n\n const dispatcher = (type: 'leading' | 'trailing') => {\n if (type === 'leading') {\n if (isNumber(throttle)) {\n dispatchThrottling(throttle)\n } else {\n dispatchThrottling(throttle.leading)\n }\n } else {\n if (isObject(throttle)) {\n dispatchThrottling(throttle.trailing)\n } else {\n throttled.value = false\n }\n }\n }\n\n onMounted(() => dispatcher('leading'))\n\n watch(\n () => loading.value,\n (val) => {\n dispatcher(val ? 'leading' : 'trailing')\n }\n )\n\n return throttled\n}\n"],"mappings":";;;AAEY,MAACA,iBAAiB,GAAGA,CAACC,OAAO,EAAEC,QAAQ,GAAG,CAAC,KAAK;EAC1D,IAAIA,QAAQ,KAAK,CAAC,EAChB,OAAOD,OAAO;EAChB,MAAME,OAAO,GAAGC,QAAQ,CAACF,QAAQ,CAAC,IAAIG,OAAO,CAACH,QAAQ,CAACC,OAAO,CAAC;EAC/D,MAAMG,SAAS,GAAGC,GAAG,CAACJ,OAAO,CAAC;EAC9B,IAAIK,aAAa,GAAG,IAAI;EACxB,MAAMC,kBAAkB,GAAIC,KAAK,IAAK;IACpC,IAAIC,WAAW,CAACD,KAAK,CAAC,EAAE;MACtBJ,SAAS,CAACM,KAAK,GAAGX,OAAO,CAACW,KAAK;MAC/B;IACN;IACI,IAAIJ,aAAa,EAAE;MACjBK,YAAY,CAACL,aAAa,CAAC;IACjC;IACIA,aAAa,GAAGM,UAAU,CAAC,MAAM;MAC/BR,SAAS,CAACM,KAAK,GAAGX,OAAO,CAACW,KAAK;IACrC,CAAK,EAAEF,KAAK,CAAC;EACb,CAAG;EACD,MAAMK,UAAU,GAAIC,IAAI,IAAK;IAC3B,IAAIA,IAAI,KAAK,SAAS,EAAE;MACtB,IAAIC,QAAQ,CAACf,QAAQ,CAAC,EAAE;QACtBO,kBAAk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