UNPKG

st-common-core

Version:

小尾巴前端通用核心库

27 lines (26 loc) 606 B
const o = ({ fun: e, tag: t = "_throttle", limit: n = 1, thisArg: r = null }) => (Reflect.defineProperty(e, t, { value: 0, writable: !0 }), async (...c) => { if (Reflect.get(e, t) >= n) return; Reflect.set(e, t, Reflect.get(e, t) + 1); const l = await e.apply(r, c); return Reflect.set(e, t, Reflect.get(e, t) - 1), l; }), i = ({ fun: e, interval: t = 500, thisArg: n = null }) => { let r = 0; return async (...c) => { const l = Date.now(); if (!(l - r < t)) return r = l, await e.apply(n, c); }; }; export { o as funThrottleByLimit, i as funThrottleByTime };