Reputation: 2523
I have a messages service that will eventually get messages saved in the database and set them globally for the user but for now I have them set like so
messages: [
Ember.Object.create({
id: 1,
name: "Out Bid",
body: "You've been out bid on an item",
read: false,
seen: false
}),
Ember.Object.create({
id: 2,
name: "Out Bid",
body: "You've been out bid on an item, You've been out bid on an item",
read: true,
seen: false
})
],
I have some computed that will tell me how many of these messages have not been marked as seen
and when I click on this bubble that shows if that number is over 0 I go to a messages
route.
In the messages
route I inject the messages
service and set the model equal to the messages that the service has in it
model() {
return this.get('messages').get('messages');
}
This route displays the messages in an each loop that renders a component
{{#each model key="id" as |message|}}
{{message-item message=message}}
{{/each}}
In the component I am trying to add the unread
class like so
classNameBindings: ['unread'],
unread: Ember.computed('message.unread',function(){
return this.get('message').get('read') === false;
}),
And that is working, however when I fire the click action to show the message in a modal and therefore mark it as read
the computed is not updating
click() {
var message = this.get('message');
this.get('notification').notify({message: message.get('body')});
message.set('read',true);
}
If I console.log
the value of message.get('read')
before and after I set it, I see that it is properly being set, but the template is not updating the computed to remove the unread
class after it's marked read.
Upvotes: 0
Views: 134
Reputation: 18682
You watch wrong property. Watch read
instead of unread
:
classNameBindings: ['unread'],
unread: Ember.computed('message.read',function(){
return this.get('message').get('read') === false;
}),
Upvotes: 1