# Did @each changed?

**URL:** https://discuss.emberjs.com/t/did-each-changed/15863
**Category:** Questions
**Created:** [November 27, 2018, 12:17pm UTC](https://discuss.emberjs.com/t/did-each-changed/15863 "2018-11-27T12:17:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ofridagan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ofridagan/32/15760_2.png) [@ofridagan](https://discuss.emberjs.com/u/ofridagan)
#### Post date: [November 27, 2018, 12:17pm UTC](https://discuss.emberjs.com/t/did-each-changed/15863/1 "2018-11-27T12:17:26Z")

</div>

Hi,

I’m pretty sure that in old ember (low 2.x), doing something like

`function(){...}.property('arr.@each.x')`

was always “stronger” than doing:

`function(){...}.property('arr')`

i.e with the @each dependency whenever some object was added to the array **OR** the array itself changed - the property would trigger its getter.

After upgrading, I noticed that defining a `arr.@each.x` dependency won’t trigger a property change when the array itself changes. Even worse, adding the two dependencies together doesn’t work!!!

I created some twiddles to clearify:

1. A working example with just `'arr'` - [working twiddle](https://ember-twiddle.com/844cd8fab74245e3567438a563e1a5da)
2. Not working using `'arr.@each.x'`- [@each not working](https://ember-twiddle.com/91daeb57fa7d802308afb671aa99d79e)
3. Not working even after adding back `'arr'` dependency - [still not working](https://ember-twiddle.com/3f05a0c543f6b71b81007cf1f1e0d724)

Did anyone else noticed that? what would be the solution if I want a recalculation of the property if either the array itself changes OR something inside it?

BTW, I think this changed in Ember 2.7… but I see nothing in the release notes…

---

<div class="post-metadata">

### Author: ![ofridagan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ofridagan/32/15760_2.png) [@ofridagan](https://discuss.emberjs.com/u/ofridagan)
#### Post date: [November 27, 2018, 1:02pm UTC](https://discuss.emberjs.com/t/did-each-changed/15863/2 "2018-11-27T13:02:12Z")

</div>

UPDATE:

I now realized that the twiddle doesn’t work because my array doesn’t contains objects only… I’m sure it worked before… but it probably makes sense.

---

<div class="post-metadata">

### Author: ![rwwagner90](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwwagner90/32/13659_2.png) [@rwwagner90](https://discuss.emberjs.com/u/rwwagner90)
#### Post date: [December 3, 2018, 3:55pm UTC](https://discuss.emberjs.com/t/did-each-changed/15863/3 "2018-12-03T15:55:50Z")

</div>

I believe the `.property` syntax is either deprecated or will be deprecated. You may want to try using `foo: computed('arr.@each.x, function(){})` etc. I could be wrong, but I think I read that somewhere.

---

<div class="post-metadata">

### Author: ![miketervela](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@miketervela](https://discuss.emberjs.com/u/miketervela)
#### Post date: [December 4, 2018, 1:13am UTC](https://discuss.emberjs.com/t/did-each-changed/15863/4 "2018-12-04T01:13:31Z")

</div>

Edit: Doh, sorry, just saw your comment where you realized the problem was objects.

If you pop open dev tools on your Example number 2 I think you’ll see a steady stream of exceptions. It seems that Ember is really unhappy trying to bind arr.@each.x to a number.

Change your [i++] to [Ember.Object.create({x:i++})]; and your counter function to return this.get(‘arr.firstObject.x’); And it works.

Change it further to this:

> **[Ember Twiddle](https://ember-twiddle.com/#/f8c125e39ba22b37184860c8cc23942e)**
>
> A web-based Ember.js code sharing tool that follows ember-cli's conventions.

And you’ll see what @each.x is really meant for.

Note that if you want to bind to an array and only care about whether it grows, shrinks, or changes, then you want to use ‘arr.’

Edit: Corrected new twiddle link

---

<div class="post-metadata">

### Author: ![miketervela](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@miketervela](https://discuss.emberjs.com/u/miketervela)
#### Post date: [December 4, 2018, 1:17am UTC](https://discuss.emberjs.com/t/did-each-changed/15863/5 "2018-12-04T01:17:03Z")

</div>

Addendum - if you take your example and as the only change, alter your ‘counter’ binding from

> }).property(‘arr.@each.x’), to }).property(‘arr.’),

then the example works - because it isn’t throwing an exception on @each.x and since ‘arr.’ correctly detects the replacement of ‘arr’.

---

<div class="post-metadata">

### Author: ![miketervela](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@miketervela](https://discuss.emberjs.com/u/miketervela)
#### Post date: [December 4, 2018, 1:26am UTC](https://discuss.emberjs.com/t/did-each-changed/15863/6 "2018-12-04T01:26:48Z")

</div>

Right now Ember extends the function prototype itself to allow things like {}.property(‘x’). If you’re working in an environment where extending this prototype is not allowed, then you need to use Ember.computed(‘x’, function()) and turn off prototype extension:

> **[Disabling Prototype Extensions - Configuration - Ember Guides](https://guides.emberjs.com/release/configuring-ember/disabling-prototype-extensions/)**
>
> By default, Ember.js will extend the prototypes of native JavaScript arrays to implement the Ember.Enumerable, Ember.MutableEnumerable, Ember.MutableArray and Ember.Array interfaces. This polyfills ECMAScript 5 array methods in browsers that do...

---

<div class="post-metadata">

### Author: ![real\_ate](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/real_ate/32/14480_2.png) [@real\_ate](https://discuss.emberjs.com/u/real_ate)
#### Post date: [January 18, 2019, 8:39am UTC](https://discuss.emberjs.com/t/did-each-changed/15863/7 "2019-01-18T08:39:42Z")

</div>

It is also important to say that `@each` has been deprecated:

[https://emberjs.com/deprecations/ember/v3.x/#toc\_getting-the-each-property](https://emberjs.com/deprecations/ember/v3.x/#toc_getting-the-each-property)

Although in your original question you say something about it changing in 2.7 🤔 I think it’s still possible (but as it’s deprecated it shouldn’t be used any more). I think it’s more likely that the `.property()` syntax isn’t working for you any more. You should consider upgrading to the new computed property syntax:

[https://guides.emberjs.com/release/object-model/computed-properties/](https://guides.emberjs.com/release/object-model/computed-properties/)
