Lodash and underscore changed the way I write Javascript forever, but today there might be better options for the most common functions.
I recentl...
For further actions, you may consider blocking this person and/or reporting abuse
Great as always :-)
I have personally never used
lodash
because there has never been a need for me to do so. I just want to point out thatlodash
is tree shakable and will not contribute to bundle size a lot expect for the functions you've imported of course.See my point about the decisions it makes around polyfilling. For these 14 functions with lodash-es - which is better designed for tree shaking - I still saved a significant amount of bundle size.
your implementation of
merge
is vulnerable to prototype pollution. You should go and read lodash's implementation before re-implementing it.portswigger.net/daily-swig/prototy...
Thanks :) Wilco
I recently added lodash to a project I'm working on.Docs are inconclusive, some recommendations I found about importing lodash functions from submodules do not work (either they were using the now deprecated standalone submodules, or something changed somewhere).
In the end I added a babel module designed to strip away the unused pieces of lodash and that gave me a very decent subset of it in my bundle.
Again, my impression? The Javascript ecosystem is a royal mess that can continue only because it has no competition.
Here here to that... :)
I'm not sure if this is a smaller implementation of your merge function, except mine returns a new value instead of mutating the first value passed in.
gist.github.com/Quozzo/3715ad741cf...
If you use
Object.assign
with an empty object/array as the first argument then it should be a non-issue either way.So... What is exactly the difference between using functions from Lodash and using your own function? Is your code lighter than Lodash just because you wrote it?
Well see above, partly down to the fact that I wrote tighter implementations with only the functionality I needed but a lot down to the face I used the same bundler to add polyfills I already need for the ones there. The different was around 22kb reduction from the tree shaken version. TBH
debounce
is probably the killer in there. But there are lots of "BaseClone" etc. Code that would work anywhere but I certainly don't use.As you can see, this isn't all of lodash-es... so tree shaking worked as far as possible:
Then, to be fair, you didn't write functions that would replace Lodash. You wrote functions that offer a subset of the functionality offered by Lodash, and that's why they are lighter.
But something that it's true is that it would be really nice if they released a version 5 of Lodash that would be compatible only with evergreen browsers. I am sure that they could get rid of a lot of code.
Yeah I did document above which functions didn't work the same. Debounce, get and set basically. I don't have the need for the advanced versions of those.
Better to tree shake it to decrease its size
Didn 't work see above. The libraries were still much bigger than my implementations.
Your
get
function won't return the value if it is0
(or any other falsy value). You'll get thedefaultValue
every time (which may be something else like"none"
).Good point, fixed.
Have you seen this? github.com/you-dont-need/You-Dont-...
See the earlier article in the series for how we use currying rather than the lodash method.
Nice. I use these: github.com/angus-c/just