Created
June 14, 2013 21:14
-
-
Save meelash/5785328 to your computer and use it in GitHub Desktop.
Workaround of issues with chaining/nesting under @each in computed properties/ bound observers: https://github.com/emberjs/ember.js/issues/541
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I wanted to do something like this: | |
App.ApplicationController = Ember.Controller.extend | |
selectedAccounts: (-> | |
accounts = [] | |
(@get 'currentUser.entities').forEach (entity)-> | |
accounts.pushObjects entity.get('accounts').filterProperty 'selected' | |
accounts | |
).property('currentUser.entities.@each.accounts.@each.selected') | |
To workaround, I did this: | |
App.ApplicationController = Ember.Controller.extend | |
selectedAccounts: (-> | |
accounts = [] | |
(@get 'currentUser.entities').forEach (entity)-> | |
accounts.pushObjects entity.get('selectedAccounts') | |
accounts | |
).property('currentUser.entities.@each.selectedAccounts') | |
App.Entity = DS.Model.extend | |
selectedAccounts: (-> | |
(@get 'accounts').filterProperty 'selected' | |
).property 'accounts.@each.selected' |
See also http://emberjs.com/blog/2013/08/29/ember-1-0-rc8.html , section Array Computed on how to get these things working without ruining performance (hopefully).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hah, just ran into some fresh work that's been done on array CP performance:
https://github.com/emberjs/ember.js/tree/master/packages/ember-runtime/lib/computed
emberjs/ember.js@fc6e2f5