Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mogadanez opened this issue Jun 24, 2014 · 4 comments

Comments

@mogadanez
Copy link

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/

kmalakoff pushed a commit that referenced this issue Jul 28, 2014
@kmalakoff
Copy link
Owner

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

@mogadanez
Copy link
Author

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/

@kmalakoff
Copy link
Owner

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?

@mogadanez
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants