Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Reset without Restarting? #58

Closed
greaturchin opened this issue Dec 27, 2018 · 1 comment
Closed

How to Reset without Restarting? #58

greaturchin opened this issue Dec 27, 2018 · 1 comment
Labels

Comments

@greaturchin
Copy link

greaturchin commented Dec 27, 2018

I would like to reset the timer to 00:00:00 without restarting it until timer.start(); is called again. Is that possible?

Or maybe another way to ask, is how can I destroy the current timer instance and create a new one with an click event?

@albert-gonzalez
Copy link
Owner

Hi!

The "stop" function sets the counters to 0, so you can listen to the 'stopped' event and then write the value. For example:

var { Timer } = require("easytimer.js");

var myTimer = new Timer();

myTimer.start();

myTimer.on('stopped', () => {
    console.log(myTimer.getTimeValues().toString());
});

myTimer.on('secondsUpdated', () => {
    console.log(myTimer.getTimeValues().toString());
    
    if (myTimer.getTimeValues().seconds >= 3) {
        myTimer.stop();
    }
});

Live example: https://runkit.com/albert-gonzalez/5c264bf92eac850012ca0e09

After that, you can start again the timer calling the "start" function.

Best Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants