Hi Chris.

I really like the idea of a Timer object. It would allow you to
separate creation from starting, allows you to pause and add other
API's to the interface. Can the constructor be used to simplify the
creation:

    var t = new Timer(0, false, function() { ...});

which would start the timer immediately, as in your example.

I think Maciej has made a convincing case that "new Timer" is a bit too coy about the fact that the timer is actually starting.

Or you could do:

    var t = new Timer(function() { ... });
    ...
    t.startOneShot(1.76);

I like your suggestion of adding "startOneShot" (and "startRepeating"?) to the API. I think it would improve clarity over a bool parameter specifying whether the timer repeats.

To create a Timer that isn't scheduled to fire:

new Timer(...)

To create a Timer that is scheduled to fire:

new Timer(...).startOneShot(...)
new Timer(...).startRepeating(...)

Or, if we don't like constructors:

createTimer(...).startOneShot(...)
createTimer(...).startRepeating(...)

And you could easily add animation or media API's for synchronization:

    var t = new Timer(1.76, function() { ... }); // when the timer is
triggered, it will run for 1.76 seconds
    var transition = window.getTransitionForElement(element, "left");
    transition.trigger(t);
    ...
    element.style.left = "100px";

This would cause the timer to start when the left transition starts
and fire its event 1.76 seconds later.

This would be really cool!

Geoff

Reply via email to