You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually, after bit thinking I realized that it's not an issue, but my wrong assumptions.
I should not listen to model remove event, without checking which collection it was removed from.
Always do the check (probably in your view), like this:
var parent = new Collection;
var child = new Collection;
var model = new Model;
var subset = new Subset({
parent: parent,
child: child,
filter: //some filter here
});
model.on('remove', function(model, collection, options) {
if (collection === child) {
//now you can be sure model was removed from child subcollection and from parent
}
});
And full test:
it 'should not trigger remove on the model', ->
filter = ->
model.get('prop') == 'val'
parent = new Collection
child = new Collection
model = new Model({id:1})
parent.add(model)
model.on 'remove', (model, collection, options)->
expect(collection).to.equal child
subset = new Subset(parent:parent,child:child,filter:filter)
expect(child.length).to.equal 0
model.set({prop: 'val'})
expect(child.length).to.equal 1
model.set({prop: null})
I will add remark in README.md to be aware of this, to not making same mistakes.
Description: When model is removed from subcollection also model remove event is triggered.
Expected: when model does not satisfy filter condition anymore, only subcollection remove event should be triggered
Actual: also model remove event is triggered
Following test will fail:
How to reproduce:
http://jsfiddle.net/mauron85/8axcsvot/3/
The text was updated successfully, but these errors were encountered: