kmalakoff/knockback

backbone-relational, troubles with batch set if already have listeners that update same model

Closed this issue · 4 comments

I have a model, and wrapped it to ViewModel

var model1 = new Model1();
var viewModel =  new ViewModel(model1);

I update model with two options:

model1.set( "propB", "val2" ); 
model1.set( { propA: "val1", propB: "val2.2" } ); 

All works fine before I have another model that listen my model and change their properties in listener

model2.listenTo(model1, "change:propA", function(){   
   model1.set("propC", "val3" );
} )

in this case batch set to model like

model1.set( { propA: "val1", propB: "val2.2" } ); 

did not update observable, and viewModel is out of date.

live sample
http://jsfiddle.net/MAZjQ/1/

Thank you for reporting this. Is should be fixed in the next release

seems issue still there.

test for this issue is not fully correct.

model1.listenTo(model1, "change:propA", function(){
   model1.set("propC", "val3" );
} )

in my example is important as well as using backbone.relational

http://jsfiddle.net/MAZjQ/8/

I've merged in the test. It looks like it passes when the atrributes are set in difference calls to set, but not in one call.

Can I clarify something? Have you definitely determined that this is a Backbone-Relational issue (issue 485) so we can wait for a patch or do you need me to investigate?

I'm pretty sure that PaulUithol/Backbone-relational#485 is a reason.

knockback use changedAttributes to determine what is changed. But Backbone-Relational loose this info in some cases since they use event queue.

For now, workaround is using setImmediate inside handler that change another model's property