Skip to content

Commit

Permalink
feat: remove lodash-es, Optimize package volume, reduce first load time
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlei3166 committed Oct 14, 2021
1 parent 50b59b1 commit c7956d9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
nextTick,
getCurrentInstance
} from 'vue'
import { throttle } from 'lodash-es'
import { throttle } from '../demoblock/throttle'
import clipboardCopy from '../demoblock/clipboard-copy'
import { stripTemplate, stripScript, stripStyle } from '../demoblock/assist'
Expand Down
45 changes: 45 additions & 0 deletions demoblock/throttle.js
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)
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"camelcase": "^6.2.0",
"globby": "^11.0.2",
"kolorist": "^1.5.0",
"lodash-es": "^4.17.20",
"markdown-it": "^12.0.4",
"minimist": "^1.2.5",
"prettier": "^2.2.1",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4170,11 +4170,6 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"

lodash-es@^4.17.20:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
Expand Down

0 comments on commit c7956d9

Please sign in to comment.