SeverinDK / moment-timer

Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.
MIT License
110 stars 33 forks source link

Add a step callback to timer arguments #3

Closed jamesSampica closed 6 years ago

jamesSampica commented 7 years ago

It would be nice to be able to configure a step function to be executed before the timer callback happens. This would make it easy to display a count down timer in html. Maybe something like this...

var redirectTimer = moment.duration(60, "seconds").timer({
    loop: false,
    start: true,
    step: { 
        delay: 1000, 
        callback: function(){ console.log("I've got " + redirectTimer.getRemainingDuration() + "ms left"); }
    }
}, function () {
    alert("times up");
});
SeverinDK commented 7 years ago

I will look into this soon :)

SeverinDK commented 7 years ago

@shoe788 - Is this still a feature you would like? You are free to do a PR for it yourself or I can do it when I have a little free time on my hands. I forgot about the issue until I saw it again just now.

aidenko commented 7 years ago

I already need this function, step callback. I tried to implement it and almost done, but realized that it would be better to create two individual timers. One "main" and another one is "step interval". Much easier and more control.