staugaard / ember-resource

This project has moved. The canonical repository is now located at: https://github.com/zendesk/ember-resource
https://github.com/zendesk/ember-resource
Apache License 2.0
122 stars 27 forks source link

Observers are not firing on property changes #22

Closed rykov closed 12 years ago

rykov commented 12 years ago

I see that SC.Resource is an extension of SC.Object, however, it doesn't look like it's respecting observers. Is this by design?

As a demo, here is some test code:

var A = SC.Object.extend({ name: null });
var B = SC.Resource.define({
  url: '/b', schema: { name: String }
});

var a = A.create({
  obs: function() { SC.Logger.info("A!!!"); }.observes('name')
});

var b = B.create({
  obs: function() { SC.Logger.info("B!!!"); }.observes('name')
});

a.set('name', 'Foo');
b.set('name', 'Bar');

This code produces the following output:

A!!!

The observer in the SC.Resource is not fired.

staugaard commented 12 years ago

You are right, and I will have a look at that. It is only broken for observers you define during creation, so this will work:

var A = SC.Object.extend({
  name: null,
  obs: function() { SC.Logger.info("A!!!"); }.observes('name')
});

var B = SC.Resource.define({
  url: '/b', schema: { name: String }
}).reopen({
  obs: function() { SC.Logger.info("B!!!"); }.observes('name')
});

var a = A.create({});

var b = B.create({});

a.set('name', 'Foo');
b.set('name', 'Bar');
rykov commented 12 years ago

Thanks for checking it out. I'll give that a shot.

staugaard commented 12 years ago

Should be good now