Have been using https://github.com/acreeger/meteor-moment in meteor and it works well, however is there a way to make the output of moment reactive so that it counts up "3 seconds ago", "4 seconds ago", etc?
Rather than using a new Session variable for each individual timer, I would create a single Tracker.Dependency
which is flagged for changes every second (or perhaps every 10 seconds), then depend on this whenever you want to depend on the current time.
var timeTick = new Tracker.Dependency();
Meteor.setInterval(function () {
timeTick.changed();
}, 1000);
fromNowReactive = function (mmt) {
timeTick.depend();
return mmt.fromNow();
}
Template.example.helpers({
example: function () {
return fromNowReactive(moment().startOf('hour'));
}
});
This is the approach taken by mizzao:timesync
, which is a useful package you can use if those fromNow
s are based on server-side timestamps. One reason to not use client-generate timestamps is that these may be out of sync, resulting in strings like 5 seconds from now
for a post that was just made. mizzao:timesync
allows server-generated timestamps to be used everywhere, and also groups different reactivity intervals together efficiently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With