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' |
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
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
Yes, this is pretty much what we ended up doing as well; but note that this will likely still give you horrible quadratic performance, because of the way changes propagate. In other words, as soon as you throw more than a handful of
accounts
at it, it will grind to a halt.The usual solution is to serve down the
selectedAccounts
list from the server, instead of trying to compute it.(Single
@each
is bad already, but I seem to recall that simulating nested@each
gets you tangled up even worse.)