Underscore -> lodash


#1

Hi all,

Was it discussed if meteor would switch from underscore to lodash in the future? Or do I have the possibility to switch to using lodash?

thanks


Impact on removing JQuery package?
Underscore version is very old (1.0.8) time to update?
#2

for your project you can use loadash but it can come to namespace problems i think


#3

meteor add alethes:lodash

Then, in a file on both client and server:

// Use lodash instead of underscore
_ = lodash;

I did this in a large, complex app that relies heavily on a whole range of underscore functions and everything works fine.


#4

There is a huge issue in regards to just that.


#5

It might be a while until they decide to switch over because it’s going to involve an astronomical amount of QA it seems, which is understandable.


#6

Does anyone know if there is an exhaustive list of incompatibilities somewhere?


#7

From what I see, lodash has everything underscore has and more. And it has quite a few optimizations in functions like _.reduce that are not in underscore.


#8

You mean like https://github.com/lodash/lodash/wiki/Migrating?


#9

I’m quite interested in this too! I have been using lodash for a long time now in other projects, but due to the way meteor and underscore seem so heavily dependent I haven’t tried switching over. It would be really cool to see some official support for lodash, as I think it’s generally considered the better library.


#10

#11

Great, but there are more projects for lodash :frowning: See https://github.com/erasaur/meteor-lodash


#12

True that. I’m using a pretty out-of-date version.


#13

I was trying to replace the built-in dependency of underscore from meteor-platform by creating a local package underscore and simply replacing underscore.js with lodash.js, however, I kept getting this error:

While preparing to build package underscore:
   error: circular dependency between packages underscore and meteor

My package.js looks like this:

Package.describe({
  name: "underscore",
  summary: "Underscore",
  version: "1.0.3"
});

Package.on_use(function(api) {
  api.add_files('lodash.js');
  api.export('_');
});

What could’ve gone wrong?

The reason I’m doing this is so that I can see whether it’ll work and maybe start testing it.


#14

Hey guys, so looks like I finally nailed it. You can replace underscore with lodash (not by installing a lodash package).

I’ve created a repository with how to do it:


Please contribute or let me know of any suggestions.

Just as a pre-emptive note, if you use iron-router (which 90% of you probably do), it will break. Just read the NOTES.md on how to fix that issue.


#15

Lazy.js is my favourite Underscore replacement; it’s not a drop in replacement like Lodash, but it is waaaay faster than either (check the benchmarks) and has all kinds of stream processing goodnes


#16

The performance tests of Lazy.js are using lodash 2.0 which I’m sure is way slower than the new lodash 3+ where they started implementing lazy evaluation. Lazy.js seems to not be active too. J. Dalton on the other hand treats lodash as if it were like drinking water.


#17

What about just updating to the latest Underscore? There’s a few features that aren’t available in the bundled version, and that always trips me up.


#18

@glasser mentions that even updating underscore has caused regressions. I’d really like for people to contribute to the repo I made for any feedback to get this going. I know time is hard to come by, but something is better than nothing.


#19

Looks like an Underscore + Lodash merge might happen.


#20

@lai lol, did you see the thread you posted? @tiandavis seemed pretty upset over there as he swung wildly at all the onlookers in the thread. creatures do that… when they fight for their last breath :slight_smile: btw, how is this looking? seriously disadvantaged being forced to use underscore. cheers.