ahawkins
ahawkins

Reputation: 1174

Ember computed property returns a filter

I have a simple property on my controller. It's used to render a list of all the emails in a conversation.

conversation: (->
  App.Email.filter (otherEmail) => 
    @get('model').isIncludedInConversation otherEmail
).property('model')

Everything works fine and dandy when I go to the page because the CP hasn't been computed yet. When I send a new email the conversation property is not updated. I need to switch what email I'm looking at to trigger conversation to recalculate.

I know the filter is being updated. The problem is the CP's value does not change and the underlying {{#each conversation}} is not updated. How can I make this work?

EDIT: I've added fiddle here: http://jsfiddle.net/twinturbo/GUeE3/1/

Upvotes: 0

Views: 177

Answers (1)

Cyril Fluck
Cyril Fluck

Reputation: 1581

I'm not familiar with coffeescript, so I assume that your code is equivalent to:

conversation: function() {
  var self = this;
  App.Email.filter( function( otherEmail ) {
    return self.get('model').isIncludedInConversation( otherEmail );
  }); 
)}.property('model')

I would be tempted to say that you should capture model outside the filter function

conversation: (->
  _model = @get('model')
  App.Email.filter (otherEmail) => 
    _model.isIncludedInConversation otherEmail
).property('model')

This code works for me with the latest version of ember and ember data.

Upvotes: 1

Related Questions