Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swap underscore 1.8.3 for lodash 4.2.1 in backbone marionette 2.4.4

Is this even possible? Keep reading conflicting reports on this.

I have a Marionette app, just upgraded to 2.4.4.

If I drop in lodash in place of underscore - using requireJS,

 map: {
  '*': {
    'underscore': 'lodash'
  }
},

//  'underscore':'/resource/vendor/backbone.marionette/underscore',
'lodash':'/resource/vendor/lodash/lodash.min',

I get the following error...

Uncaught TypeError: Cannot read property 'vent' of undefined

lodash is loading up ok, just marionette is complaining.

It appears that the context this on line 466 is undefined

 463 _proxyMethods: function() {
 464     _.each([ "vent", "commands", "reqres" ], function(system) {
 465       _.each(messageSystems[system], function(method) {
 466         this[system][method] = proxyMethod(this, system, method);
 467       }, this);
 468     }, this);
 469   }

Any advice?

like image 885
Matt Bryson Avatar asked Feb 06 '16 02:02

Matt Bryson


People also ask

Is lodash compatible with underscore?

Because Lodash is updated more frequently than Underscore. js, a lodash underscore build is provided to ensure compatibility with the latest stable version of Underscore.

Is underscore and lodash the same?

Lodash's API is a superset of Underscore. It provides every functionality that Underscore does, along with a few additional helpful functions such as AMD support, deep clone, and deep merge.

Why is lodash called lodash?

That's just a name. A short name, used for namespacing the library. lodash can be considered a fork of the underscore, a light version of underscore.


1 Answers

For anyone else looking at this, the answer is no.

Lodash 3.10.1 is fine, but the 4.x release has removed the context option from many of the functions, which breaks Marionette.

The old way was

    _.each(collection, iteratee, context);

The new way is

_.each(collection, _.bind(iteratee, context));

But so far so good with using 3.10.1 with the above requireJS set up.

So until Marionette is updated, you have to hold off on 4.x

like image 179
Matt Bryson Avatar answered Sep 27 '22 22:09

Matt Bryson