Improving Ember.computed for Arrays


Interested in what Ember computed properties might be worthy of being in core. I specifically wish there was more support for array operations like slice, first, and last.

@jamesarosen has a great third party lib full of some:

I just opened up a PR here for adding Ember.computed.slice here:

Another idea I had was a generic computed property that just passes through the method to the dependent object. Example:

Ember.computed.send('arrayKey', 'slice', 0, 1) Ember.computed.send('objectKey', 'keys')


Great idea. I like having computed properties for simple stuff. However if we need to call a method, wouldn’t it be better to just have a computed property bases on a function?

function () { @get('arrayKey').slice(0,1) }.property('arrayKey')

I don’t like that this style isn’t super dry, but we already have a simple way of calling methods and I don’t feel like we need another syntax for it (it wouldn’t hurt me to ignore it though if it made it into core)

I think it would be useful for first, last, maybe even mapBy, filterBy, findBy I can see some use.

selectedPerson: Ember.findBy('id', 10).in(people)

We could even nest them to create more powerful expressions and IMO that’s where the real value comes in

canDrink: Ember.gte('selectedPerson.age', 21)