Observer similar to @each but on object instead of array


#1

Hi,

I need to set an observer for tracking changes in object keys. Let’s say, like below:

App.Something = Ember.Object.extend({
  updatePropTest: function(){
    console.log(333, "XXX"); // XXX
  }.observes("info.@each"),
});
...
obj = App.Something.create();
obj.set("info.name");

But as you know, @each doesn’t cover it.

Any idea?


#2

Here is how I’ve done it in the past http://jsfiddle.net/NQKvy/1014/


#3

Hi, thanks. I’ve done something similar too but I thought there was a “right” way under Ember’s specs.


#4

Yea, there is a few ways to do it. Though, I don’t think there is any “official” ember-way.


#5

Perhaps setUnknownProperty is what you need?

http://jsfiddle.net/NQKvy/1016/

There is also a parallel unknownProperty function which is fired when you try to get a property that does not exist


#6

Hummm, that really looks to be what I’m searching for :slight_smile: I will know it a bit more, thank you @alexspeller