decord/source/635_throttle.js

38 lines
898 B
JavaScript
Raw Normal View History

2026-07-29 08:29:29 +00:00
// Module ID: 635
// Function ID: 636
2026-07-20 16:05:17 +00:00
// Name: throttle
2026-07-29 08:29:29 +00:00
// Dependencies: [606, 636]
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
// Module 635 (throttle)
2026-08-24 06:08:38 +00:00
import isObject from "isObject" /* 606 */;
import debounce from "debounce" /* 636 */;
2026-07-20 16:05:17 +00:00
2026-08-04 21:03:28 +00:00
export default function throttle(fn, arg1, leading) {
if (typeof fn !== "function") {
2026-07-20 16:05:17 +00:00
const _TypeError = TypeError;
const typeError = new TypeError("Expected a function");
throw typeError;
} else {
let flag3 = true;
2026-07-29 08:29:29 +00:00
let flag4 = true;
2026-08-24 06:08:38 +00:00
if (isObject(leading)) {
2026-07-20 16:05:17 +00:00
let flag = true;
if ("leading" in leading) {
flag = leading.leading;
}
let flag2 = true;
if ("trailing" in leading) {
flag2 = leading.trailing;
}
flag3 = flag2;
flag4 = flag;
}
2026-07-29 08:29:29 +00:00
const obj = { leading: null, maxWait: null, trailing: null };
obj[0] = flag4;
obj[1] = arg1;
obj[2] = flag3;
2026-08-24 06:08:38 +00:00
return debounce(fn, arg1, obj);
2026-07-20 16:05:17 +00:00
}
};