Search code examples
javascriptbackbone.jsunderscore.jsmarionettelodash

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?


Solution

  • 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