0
votes

Here are my steps:

  1. declare extended collection of Backbone colleciton: extenedCollection = $.extend({}, backboneCollection, decorator);

  2. Build composite view with the extended collection.

  3. Do extenedCollection.remove(xModel);

Expected result: The composite view will catch the remove event and will remove the relevant item view from the composite view.

Actual result: Backbone's remove() function fire "remove" event. Marionette in _initialEvents listening on the "remove" event, but not catch the remove event when fired, and therfore not execute the function "removeItemView".

Comment: With the code extenedCollection = $.extend(backboneCollection, decorator); all works fine. But I must create new object when extending the original backbone collection.

Help?

1

1 Answers

1
votes

Why not use the built in Backbone.Collection.extend functionality? It is designed for the use case you are talking about.

// Extend Backbone types with the Backbone.extend function
var MyCollectionType = Backbone.Collection.extend(MyDecorator);

var myCollection = new MyCollectionType(models);
var myCompositeView = new MyAwesomeCompositeView({collection : myCollection});

// Not necessary.
myCompositeView.onItemRemoved = function () {
  console.log(arguments);
};

myCollection.remove(myModel); // Event is handled by composite view