I am creating list of messages that shows how long ago the message was sent.
This is my messages collection
Messages = new Mongo.Collection('messages');
Messages.attachSchema(new SimpleSchema({
created: {
type: Date
},
text: {
type: String
}
}));
this my my layout
{{#each messages}}
<li class="message">
<span class="message-text">{{text}}</span>
<span class="message-date">{{timeAgo created}}</span>
</li>
{{/each}}
This is my helper
UI.registerHelper('timeAgo', function (context, options) {
if (context) {
return moment(context).fromNow();
}
});
How can i make it so that my helper updates each minute? Right now it is not reactive unless I enter a new message or refresh the page.
UPDATE
Meteor-livestap does exactly this .
Change your helper to this:
What this does is change
Session.get("time")
every minute, and forces your helper to recalculate. This should ensure the time stays reactive every minute.