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

Bindings not syncing before save() #23

Open
rykov opened this issue Nov 29, 2011 · 1 comment
Open

Bindings not syncing before save() #23

rykov opened this issue Nov 29, 2011 · 1 comment

Comments

@rykov
Copy link

rykov commented Nov 29, 2011

I am chaining the saving of a few resources. When the first resource is saved, it is updated with the ID that I need to save the second resource (via a binding). However, when I use jQuery.Deferred callbacks to trigger the chain, the bindings from the first objects don't propagate to the second object.

I'm wondering whether it makes sense to call SC.run.sync() before calling toJSON() in the save() function. I'm not sure whether it's the best solution to do it synchronously because the save() call might be tied to a user action.

Here's some demo code that manifests the issue:

R = SC.Resource.define({
  url: '/url',
  schema: {
    id:  String,
    foo: String
  }
});

Demo = SC.Application.create({
  foo: 'hello',
  r: R.create({
    fooBinding: 'Demo.foo'
  })
});

// run.once() to allow the original value to sync
SC.run.once(Demo, function() {
  Demo.set('foo', 'world');
  Demo.r.save();
});

In this test, foo=hello is sent to the server, not foo=world

@staugaard
Copy link
Owner

Yeah a SC.run.sync() call might be a good idea in toJSON or save. Have you tried adding it?

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