-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove lodash-es, Optimize package volume, reduce first load time
- Loading branch information
1 parent
50b59b1
commit c7956d9
Showing
4 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* js节流 | ||
* @param method | ||
* @param delay | ||
* @return {Function} | ||
*/ | ||
export function throttle(method, delay) { | ||
let timer = null | ||
let begin = new Date() | ||
return function () { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const context = this, | ||
args = arguments | ||
const current = new Date() | ||
const remaining = delay - (current - begin) | ||
clearTimeout(timer) | ||
if (remaining <= 0) { | ||
method.apply(context, args) | ||
begin = new Date() | ||
} else { | ||
timer = setTimeout(function () { | ||
method.apply(context, args) | ||
}, remaining) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 函数防抖 | ||
* @param method | ||
* @param delay | ||
* @return {Function} | ||
*/ | ||
export function debounce(method, delay) { | ||
let timer = null | ||
return function () { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const context = this, | ||
args = arguments | ||
clearTimeout(timer) | ||
timer = setTimeout(function () { | ||
method.call(context, args) | ||
}, delay) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters