phetsims / utterance-queue

Alerting library powered by aria-live
MIT License
0 stars 2 forks source link

Support building as an independent library #6

Closed zepumph closed 4 years ago

zepumph commented 4 years ago

From #1, it would be nice if this could bundle into its own buildable, like scenery. We go most of the way in #1 just supporting this as a dependency to a buildable, standalone scenery. I think following dot/kite etc will be straightforward.

zepumph commented 4 years ago

@twant and I added this logic, we decided to experiment with implementing these from globals on phet instead of just on window, as is the way of the future, see https://github.com/phetsims/scenery/issues/966.

@jessegreenberg please review commits here. You can test this by running cd utterance-queue; grunt and then running an html scrap like this:

<script src="../sherpa/lib/lodash-4.17.4.js"></script>

<script src="../utterance-queue/build/utterance-queue.min.js"></script>
jessegreenberg commented 4 years ago

It is fun to see this as an independent lib! I was able to get a test example running with the following:

<head>
  <script src="../sherpa/lib/lodash-4.17.4.js"></script>
  <script src="../utterance-queue/build/utterance-queue.min.js"></script>
</head>

<body></body>
<script>
  const utteranceQueue = new phet.utteranceQueue.UtteranceQueue( false );
  const container = utteranceQueue.getAriaLiveContainer();
  document.body.appendChild( container );

  let lastTime = 0;

  window.setInterval( () => {
    utteranceQueue.addToBack( 'This is a test.' );
  }, 2000 );

  function step() {
    const time = Date.now();
    const elapsedTimeMilliseconds = ( lastTime === -1 ) ? ( 1000.0 / 60.0 ) : ( time - lastTime );
    lastTime = time;

    // Convert to seconds
    const dt = elapsedTimeMilliseconds / 1000.0;

    phet.axon.timer.emit( dt );
    window.requestAnimationFrame( step );
  }
  window.requestAnimationFrame( step );

</script>
jessegreenberg commented 4 years ago

Here are the things I noticed, maybe new issues should be made rather than addressing all of them here. Some of them are related to building as an independent library, others are related to documentation. I will let @zepumph decide.

zepumph commented 4 years ago

Added doc to stepSimulation above.

zepumph commented 4 years ago

Usage of utteranceQueue requires us step axon.timer. Related to the previous point, documentation about sim.stepSimulation should indicate that axon.timer.emit is required.

I wonder if the standalone build could have a script that automatically does this, to make for an easier "hello world". Could be worth experimenting with a bit.

zepumph commented 4 years ago

Usage of utteranceQueue requires us step axon.timer. Related to the previous point, documentation about sim.stepSimulation should indicate that axon.timer.emit is required.

This is the current doc in Sim.stepSimulation. I think it is good as is:

      // timer step before model/view steps, see https://github.com/phetsims/joist/issues/401
      // Note that this is vital to support Interactive Descriptions and the utterance queue.
      timer.emit( dt );
zepumph commented 4 years ago

I created fromFactory as a nicer hello world. Please also review the new and improved README. I also checked in the minified lib. That has worked well in scenery and I think it is a great place to start. Please review.

jessegreenberg commented 4 years ago

I created fromFactory as a nicer hello world.

Wow, this is so cool! Thank you! I tried it out and it was as easy as copy and paste.

The other documentation additions look great too.

Closing this issue.