How timers should ideally be implemeted?

Hi there!

So, I have a button in a template that appears with a helper function defined with {{#if helper}} which is linked to a DB field which is related to another method etc…

What I want to do is that I want that button to appear with a delay. Of course JS/JQ way of doing it is with a timer. But I know I’m going to need this a lot in the future and I want to learn and implement the most ideal Meteor way. Not a dirty counter or setTimeOut please :smiley: .

Any advice or link to a github page??

Many thanks!
Emin

you can use css transitions (they support delay)

Template['your_template'].onRendered(function () {
  $(this.find('button')).delay(5000).fadeIn('slow');
});

Thing is, the delay is a matter of days; not seconds. Therefore it must be a backend solution I believe (no??).

Another tip is that the helper I’m using to detect the field (with if exists) stores the date of the field’s creation as data, with new Date(). So I can use that date there to track and show that button if the date now is at least, say, 3 days after that registered date.

So, I’d say I need to:

  1. Get the date now,
  2. Compare with the registered date in the field,
  3. Write a function that includes a variable (var delayTime = 3 days) to run the function accordingly.

Any thoughts…?

Looks like there’s a neat library called momentjs: http://momentjs.com/

and a meteor package: https://atmospherejs.com/momentjs/moment

Any review?

Do you mean something like a synced cron?

Hmm, this also looks good. But the special case of this one seems to be large scale applications and recursive functions, right??