Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programatically fire tick event

ANSWERED

Hey,

I'm currently creating yet another clock and I need to show the current time in a label based on a toggle in my settings page.

Sounds easy but my clock granularity is set to minutes so my user would have to wait up to ~59 seconds to see the changes.

Is there any way to kinda fire a new tick event programatically?

Best regards,
wrnr

Best Answer
1 BEST ANSWER

Accepted Solutions

There are many ways; here's mine. You can direct the clock.ontick event handler to a named function like this:

clock.ontick = evt => {onTick(evt.date)}

You declare your handler function like this:

function onTick(now) {...

When you need that function to run because you've changed something on which it depends (eg, setting):

onTick(new Date())
Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
2 REPLIES 2

There are many ways; here's mine. You can direct the clock.ontick event handler to a named function like this:

clock.ontick = evt => {onTick(evt.date)}

You declare your handler function like this:

function onTick(now) {...

When you need that function to run because you've changed something on which it depends (eg, setting):

onTick(new Date())
Peter McLennan
Gondwana Software
Best Answer

Thank you! This works

Best Answer