Skip to content

Commit

Permalink
Rename timer => stepTimer, see phetsims/axon#329
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Sep 11, 2020
1 parent 5a0003c commit bd4c071
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions js/accessibility/KeyStateTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import Emitter from '../../../axon/js/Emitter.js';
import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import scenery from '../scenery.js';
import KeyboardUtils from './KeyboardUtils.js';

Expand All @@ -36,11 +36,11 @@ class KeyStateTracker {
this.keyupEmitter = new Emitter( { parameters: [ { valueType: Event } ] } );

const stepListener = this.step.bind( this );
timer.addListener( stepListener );
stepTimer.addListener( stepListener );

// @private
this._disposeKeystateTracker = () => {
timer.removeListener( stepListener );
stepTimer.removeListener( stepListener );

if ( this.attachedToDocument ) {
this.detachFromDocument();
Expand Down
10 changes: 5 additions & 5 deletions js/accessibility/KeyStateTrackerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


// modules
import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import KeyboardUtils from './KeyboardUtils.js';
import KeyStateTracker from './KeyStateTracker.js';

Expand All @@ -37,15 +37,15 @@ QUnit.module( 'KeyStateTracker', {

before() {

// step the timer, because utteranceQueue runs on timer
// step the stepTimer, because utteranceQueue runs on stepTimer
let previousTime = Date.now();
intervalID = setInterval( () => { // eslint-disable-line bad-sim-text
const currentTime = Date.now();
const timeStep = ( currentTime - previousTime ) / 1000; // convert to seconds
previousTime = currentTime;

// step timer
timer.emit( timeStep );
stepTimer.emit( timeStep );
}, 10 );
},
after() {
Expand Down Expand Up @@ -125,12 +125,12 @@ QUnit.test( 'test tracking with time', async assert => {
let currentTimeDown = testTracker.timeDownForKey( spaceKeyDownEvent.keyCode );
assert.ok( currentTimeDown === 0, 'should be zero, has not been down any time' );

timer.setTimeout( () => { // eslint-disable-line bad-sim-text
stepTimer.setTimeout( () => { // eslint-disable-line bad-sim-text
currentTimeDown = testTracker.timeDownForKey( spaceKeyDownEvent.keyCode );

assert.ok( currentTimeDown >= firstPressTime && currentTimeDown <= totalPressTime, 'key pressed for ' + firstPressTime + ' ms' );

timer.setTimeout( () => { // eslint-disable-line bad-sim-text
stepTimer.setTimeout( () => { // eslint-disable-line bad-sim-text
currentTimeDown = testTracker.timeDownForKey( spaceKeyDownEvent.keyCode );

assert.ok( currentTimeDown >= totalPressTime, 'key pressed for ' + secondPressTime + ' more ms.' );
Expand Down
6 changes: 3 additions & 3 deletions js/accessibility/KeyboardFuzzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import Random from '../../../dot/js/Random.js';
import Display from '../display/Display.js';
import scenery from '../scenery.js';
Expand Down Expand Up @@ -81,7 +81,7 @@ class KeyboardFuzzer {
*/
clearListeners() {
this.keyupListeners.forEach( function( listener ) {
timer.clearTimeout( listener );
stepTimer.clearTimeout( listener );
listener();
} );
}
Expand Down Expand Up @@ -116,7 +116,7 @@ class KeyboardFuzzer {
// TODO: screen readers normally take our keydown events, but may not here, is the descrpency ok?
this.triggerDOMEvent( KEY_DOWN, element, keyCode );

this.keyupListeners.push( timer.setTimeout( () => {
this.keyupListeners.push( stepTimer.setTimeout( () => {
this.triggerDOMEvent( KEY_UP, element, keyCode );

}, this.random.nextInt( MAX_MS_KEY_HOLD_DOWN ) ) );
Expand Down
4 changes: 2 additions & 2 deletions js/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Emitter from '../../../axon/js/Emitter.js';
import Property from '../../../axon/js/Property.js';
import PropertyIO from '../../../axon/js/PropertyIO.js';
import TinyProperty from '../../../axon/js/TinyProperty.js';
import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import Dimension2 from '../../../dot/js/Dimension2.js';
import Matrix3 from '../../../dot/js/Matrix3.js';
import escapeHTML from '../../../phet-core/js/escapeHTML.js';
Expand Down Expand Up @@ -1083,7 +1083,7 @@ inherit( Object, Display, extend( {
lastTime = timeNow;

// step the timer that drives any time dependent updates of the Display
timer.emit( timeElapsedInSeconds );
stepTimer.emit( timeElapsedInSeconds );

stepCallback && stepCallback( timeElapsedInSeconds );
self.updateDisplay();
Expand Down
6 changes: 3 additions & 3 deletions js/listeners/KeyboardDragListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import Vector2 from '../../../dot/js/Vector2.js';
import inherit from '../../../phet-core/js/inherit.js';
import merge from '../../../phet-core/js/merge.js';
Expand Down Expand Up @@ -128,11 +128,11 @@ function KeyboardDragListener( options ) {

// step the drag listener, must be removed in dispose
const stepListener = this.step.bind( this );
timer.addListener( stepListener );
stepTimer.addListener( stepListener );

// @private - called in dispose
this._disposeKeyboardDragListener = function() {
timer.removeListener( stepListener );
stepTimer.removeListener( stepListener );
};
}

Expand Down
10 changes: 5 additions & 5 deletions js/listeners/PressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Action from '../../../axon/js/Action.js';
import BooleanProperty from '../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../axon/js/DerivedProperty.js';
import ObservableArray from '../../../axon/js/ObservableArray.js';
import timer from '../../../axon/js/timer.js';
import stepTimer from '../../../axon/js/stepTimer.js';
import inherit from '../../../phet-core/js/inherit.js';
import merge from '../../../phet-core/js/merge.js';
import EventType from '../../../tandem/js/EventType.js';
Expand Down Expand Up @@ -455,8 +455,8 @@ inherit( Object, PressListener, {
if ( this.a11yClickingProperty.value ) {
this.interrupted = true;

if ( timer.hasListener( this._a11yClickingTimeoutListener ) ) {
timer.clearTimeout( this._a11yClickingTimeoutListener );
if ( stepTimer.hasListener( this._a11yClickingTimeoutListener ) ) {
stepTimer.clearTimeout( this._a11yClickingTimeoutListener );

// interrupt may be called after the PressListener has been disposed (for instance, internally by scenery
// if the Node receives a blur event after the PressListener is disposed)
Expand Down Expand Up @@ -834,10 +834,10 @@ inherit( Object, PressListener, {
else {
// if we are already clicking, remove the previous timeout - this assumes that clearTimeout is a noop if the
// listener is no longer attached
timer.clearTimeout( this._a11yClickingTimeoutListener );
stepTimer.clearTimeout( this._a11yClickingTimeoutListener );

// now add the timeout back to start over, saving so that it can be removed later
this._a11yClickingTimeoutListener = timer.setTimeout( () => {
this._a11yClickingTimeoutListener = stepTimer.setTimeout( () => {

// the listener may have been disposed before the end of a11yLooksPressedInterval, like if it fires and
// disposes itself immediately
Expand Down

0 comments on commit bd4c071

Please sign in to comment.