tomasbasham
tomasbasham

Reputation: 1734

Coffescript and Ember.js computed properties

I need some help converting some javascript into coffeescript to be used with ember. Specifically it is to do with computed properties. I have the following javascript code:

Portal.AppsController = Ember.ArrayController.extend({
    sortProperties: ['name'],
    sortAscending: true,

    appsCount: function() {
        return this.get('model.length');
    }.property('@each'),

    updated: function() {
        return this.get('model.modified');
    }.property('modified')
});

What I am tempted to do is simply:

removed for brevity
...
appsCount: ->
    @get 'model.length'
.property '@each'
...

but this is not valid syntax. Is this actually possible?

Upvotes: 0

Views: 153

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

For computed properties you need to wrap it

appsCount: (->
  @get 'model.length'
).property '@each'

http://emberjs.jsbin.com/ikatIwaB/1/edit

daLength:  (->
  @get 'length'
).property 'length'

BTW, I know a few people that are using Ember Script to solve most of the issues you are probably seeing http://emberscript.com/

Upvotes: 2

Related Questions