"Re-run" template helpers?

I’ve got an ‘activity log’ template that uses Moment.js to display fromNow times. What’s the canonical way, if any, to ‘re-run’ the template helpers and refresh the times, say, every minute?

Apologies if this is already clearly answered somewhere, I haven’t been able to find it :slight_smile:

I use https://atmospherejs.com/remcoder/chronos

1 Like

How about timers https://docs.meteor.com/api/timers.html ?

Oh wow, this looks perfect!

That’s what I was going to do, but I am still not sure exactly what the recurring function would do. Manually invalidate something? I’m not using reactive vars, so I don’t know how I’d do this without adding a bunch of additional complexity?

What are you using then, can you show some code?

I am using a ReactiveVar in combination with Meteor.interval() for live timestamps, and this is not complex at all:

  • initialize the ReactiveVar in onCreated()
  • start the interval to update the ReactiveVar as required
  • clear the interval in onDestroyed()

In order to access the ReactiveVar inside the template without the need to define a helper for it, I am using this method:

This saves a lot of boilerplate code.

Did not know about the remcoder:chronos package, though. Looks interesting.

Sure, that’s what I figured; by complex I just meant more complex than doing none of that at all :wink: Which, it turns out, Chronos allowed me to do. Pretty sweet!