update docs

This commit is contained in:
Harvey Zack committed 2023-05-13 21:57:45 +08:00
1 parent 84c84e4cda
commit e3e42eb399
115 files changed
+279 -598

No files matched your search

+18 -32
View File
@@ -2,45 +2,31 @@ export function sleep(ms = 0) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export function debounce(func, wait, context) {
export function debounce(func, duration) {
let timeout;
function fn(...args) {
const later = function later() {
return function (...args) {
const effect = () => {
timeout = null;
func.apply(context, args);
return func.apply(this, args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
}
fn.clearTimeout = function ct() {
clearTimeout(timeout);
timeout = setTimeout(effect, duration);
};
return fn;
}
export function throttle(callback, delay) {
let isThrottled = false;
let args;
let context;
function fn(...args2) {
if (isThrottled) {
args = args2;
context = this;
return;
export function throttle(func, duration) {
let shouldWait = false;
return function (...args) {
if (!shouldWait) {
func.apply(this, args);
shouldWait = true;
setTimeout(function () {
shouldWait = false;
}, duration);
}
isThrottled = true;
callback.apply(this, args2);
setTimeout(() => {
isThrottled = false;
if (args) {
fn.apply(context, args);
args = null;
context = null;
}
}, delay);
}
return fn;
};
}