移除两个依赖

This commit is contained in:
Harvey Zack committed 2019-06-06 13:32:19 +08:00
1 parent dc8337dc65
commit 98c600c244
10 files changed
+257 -368

No files matched your search

+25
View File
@@ -61,6 +61,31 @@ export function debounce(func, wait, context) {
return fn;
}
export function throttle(callback, delay) {
let isThrottled = false;
let args;
let context;
function fn(...args2) {
if (isThrottled) {
args = args2;
context = this;
return;
}
isThrottled = true;
callback.apply(this, args2);
setTimeout(() => {
isThrottled = false;
if (args) {
fn.apply(context, args);
args = null;
context = null;
}
}, delay);
}
return fn;
}
export function mergeDeep(...objects) {
const isObject = item => item && typeof item === 'object' && !Array.isArray(item);
return objects.reduce((prev, obj) => {