chrisguttandin / timing-object

An implementation of the timing object specification.
MIT License
38 stars 1 forks source link

addEventListener('timeupdate', ...) is not working #226

Closed igorveremsky closed 3 years ago

igorveremsky commented 3 years ago

Hi, great stuff, thank you for maintaining it, btw, i want to know do you implement a timeupdate event. At specification it exist but when i try to do:

this.timingObject.addEventListener('timeupdate', (e) => {
  var vector = this.timingObject.query();
  console.log(e, vector);
  console.log("pos:" + vector.position +
      " vel:" + vector.velocity +
      " acc:" + vector.acceleration);
});

nothing happens @chrisguttandin can you look it, pls.

chrisguttandin commented 3 years ago

Hi @igorveremsky, thanks for your nice words.

The timeupdate event is not implemented. I added a little note to the readme but it can probably be missed very easily.

The reason why I did that is because I don't believe it's very useful. The spec says it should fire "periodically with [a] fixed frequency [of] 5Hz". I think it is not possible to implement anything in the browser which fires with a constant frequency. Not even for the browser vendors. Furthermore my thinking is something that fires at a more or less constant frequency might be useful for some scenarios but not for others. It will most likely either fire too often or not often enough.

If you need that functionality to change the UI, I would recommend to set up a loop with requestAnimationFrame() instead.

requestAnimationFrame(function updateUI () {
     const vector = this.timingObject.query();

      // do something with the vector...

     requestAnimationFrame(updateUI);
});

Does that help?

igorveremsky commented 3 years ago

yes it helps, thanks. Also think that notice at readme need to be more noticeable, with some text hint style, but its up to you. Thanks again and sry for long reply.