3v0k4
3v0k4

Reputation: 161

Ember: how to fire observers when any Em.A inside an Em.Object change

Let's say I have something like

property: Em.Object.create(foo: Em.A([]), bar: Em.A([])),

onAnyArrayChange: function(){
//some code
}.observes('WHAT HERE??')

Thing is I don't want to explicitly say

.observes('property.foo.[]', 'property.bar.[]')

I'd love something like

.observes('property.EACH_KEY.[]')

Is there a way to do it?

Upvotes: 0

Views: 158

Answers (1)

givanse
givanse

Reputation: 14943

Yes it is possible with the @each property. See: http://emberjs.com/api/classes/Ember.Array.html#property__each

What you need to do is convert your property from an Ember.Object into an Ember.ArrayProxy like this:

property: Em.ArrayProxy.create({
  content: [
    Em.A([]), // used to be foo
    Em.A([]) // used to be bar
  ]
});

And now you can:

.observes('property.@each.[]')

Upvotes: 1

Related Questions