backbone-associations
backbone-associations copied to clipboard
Events behaviour with ListenTo different with On
Hello, It seems that "listenTo" doesnt have the same behaviour as "on".
My code:
var Model3 = Backbone.AssociatedModel.extend({}); var Model1 = Backbone.AssociatedModel.extend({}); var Model2 = Backbone.AssociatedModel.extend({ relations: [ {key: 'm1', relatedModel: Model1, type: 'One'} ] });
With listento:
m.listenTo(m2, 'change:m1.bla', ()=>{ console.log("bla"); }); m.listenTo(m2, 'change:m1', ()=>{ console.log("m1 change"); }); m2.set({m1}); m1.set('bla', 4545);
With on:
m2.on('change:m1.bla', ()=>{ console.log("bla"); }); m2.on('change:m1', ()=>{ console.log("m1 change"); }); m2.set({m1}); m1.set('bla', 4545);
With "on", "bla" and "m1 change" are triggered, but with listento, "bla" is not triggered.
I need to use listento because a third component (a view) listen to different objects events when the view is mounted, and all events are then clear when the view is unmounted. Doesn't anyone have an idea how to do a workaround ?
thank you and have a good day
Dorian