-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace lodash with native API #3753
Comments
Also, benchmarks are needed to see if the generation becomes faster after we remove lodash. |
@curbengh We might drop in helpers & filters first, which might not cause any breaking changes and can be done in v4. |
Currently, there is no better ways to replace |
One annoyance I found with lodash's // Sample _config
const hexo = { aaa: { bbb: undefined } }
hexo.aaa = Object.assign({ bbb: 'ccc' }, hexo.aaa)
// undefined
hexo.aaa = _.defaults({ bbb: 'ccc' }, hexo.aaa)
// 'ccc'
hexo.aaa = _.defaultsDeep({ bbb: 'ccc' }, hexo.aaa)
// 'ccc'
hexo.aaa = _.merge({ bbb: 'ccc' }, hexo.aaa)
// 'ccc'
hexo.aaa = _.assign({ bbb: 'ccc' }, hexo.aaa)
// undefined
hexo.aaa = _.assignIn({ bbb: 'ccc' }, hexo.aaa)
// undefined
hexo.aaa = _.extend({ bbb: 'ccc' }, hexo.aaa)
// undefined A quirk with // User config
const hexo = { aaa: { bbb: 'custom' } }
hexo.aaa = _.defaults({ bbb: 'ccc' }, hexo.aaa)
// 'ccc'
hexo.aaa = _.defaults(hexo.aaa, { bbb: 'ccc' })
// 'custom' But it doesn't replace null though 😞 const hexo = { aaa: { bbb: null } }
hexo.aaa = _.defaults(hexo.aaa, { bbb: 'ccc' })
// null |
I have tried |
I have nearly finished: function extend(...args) {
for (let i < args.length - 1; i >= 0; --i) {
for (const key in args[i])
args[0][key] = args[i][key];
}
return args[0];
} The And unfortunately, the The config, theme config along with lodash itself was bind to Lines 359 to 365 in e423773
|
Feature Request
The idea came from hexojs/site#1139 (comment) & #3677.
There is an article suggests we don't need lodash anymore.
According to benchmark below we can see es6 performance more or less as same as Lodash, in term of CPU, Memory or Handling time, at least in browser.
There are also some benchmark of lodash vs es6 and es6 is definitely much faster in browser:
IMHO, we might consider replace at least some lodash with native js.
A guide about how to replace lodash with es6: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
A list of files that requires lodash:
hexo
lib/hexo/index.jsWe might start with lib located under
lib/plugins/
warehouse
cc @curbengh @segayuu
The text was updated successfully, but these errors were encountered: