From febc9f3d17b683738c3fd18763e2420d1b0c9f43 Mon Sep 17 00:00:00 2001 From: jbphet Date: Wed, 23 Mar 2022 16:19:18 -0600 Subject: [PATCH] TS conversion step, see https://github.com/phetsims/tambo/issues/160 --- .../sim-like-components/model/BoxOfBalls.ts | 10 +++--- .../model/SimLikeComponentsModel.ts | 33 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/js/demo/sim-like-components/model/BoxOfBalls.ts b/js/demo/sim-like-components/model/BoxOfBalls.ts index fdcc8818..b4609c2f 100644 --- a/js/demo/sim-like-components/model/BoxOfBalls.ts +++ b/js/demo/sim-like-components/model/BoxOfBalls.ts @@ -26,15 +26,15 @@ const createRandomColor = () => { }; class BoxOfBalls { + + // an array the contains the balls that are in this box + public readonly balls: ObservableArray; + + // the bounding box private readonly box: Shape; - private readonly balls: ObservableArray; constructor( width: number, height: number ) { - - // @public (read-only) {Shape.rect} - the bounding box this.box = Shape.rect( 50, 0, width, height ); - - // @public (read-only) {ObservableArrayDef} this.balls = createObservableArray(); } diff --git a/js/demo/sim-like-components/model/SimLikeComponentsModel.ts b/js/demo/sim-like-components/model/SimLikeComponentsModel.ts index 2583b2ba..ed5b5c50 100644 --- a/js/demo/sim-like-components/model/SimLikeComponentsModel.ts +++ b/js/demo/sim-like-components/model/SimLikeComponentsModel.ts @@ -1,7 +1,5 @@ // Copyright 2018-2020, University of Colorado Boulder -// @ts-nocheck - /** * A model that exists only for the purposes of demonstrating sonification, particularly how view and model elements are * used together to hook up sonification elements. @@ -16,24 +14,26 @@ import BoxOfBalls from './BoxOfBalls.js'; class SimLikeComponentsModel { - /** - * @constructor - */ - constructor() { + // a box containing bouncing balls + public readonly boxOfBalls: BoxOfBalls; - // @public (read-only) {BoxOfBalls) - box containing bouncing balls, size empirically determined - this.boxOfBalls = new BoxOfBalls( 135, 80 ); + // controls the number of balls in the box + public readonly numberOfBallsProperty: NumberProperty; - // @public {NumberProperty} - controls the number of balls in the box - this.numberOfBallsProperty = new NumberProperty( 0 ); + // controls whether the balls are bouncing around in the box or still + public readonly ballsMovingProperty: BooleanProperty; - // @public {BooleanProperty} - controls whether the balls are bouncing around in the box or still - this.ballsMovingProperty = new BooleanProperty( false ); + // tracks whether a reset is happening + public readonly resetInProgressProperty: BooleanProperty; - // @public {BooleanProperty} - tracks whether a reset is happening + constructor() { + + this.boxOfBalls = new BoxOfBalls( 135, 80 ); // size empirically determined + this.numberOfBallsProperty = new NumberProperty( 0 ); + this.ballsMovingProperty = new BooleanProperty( false ); this.resetInProgressProperty = new BooleanProperty( false ); - // add or remove balls as the count changes + // Add or remove balls as the count changes. this.numberOfBallsProperty.link( desiredNumberOfBalls => { const numberBallsInBox = this.boxOfBalls.balls.lengthProperty.get(); if ( desiredNumberOfBalls > numberBallsInBox ) { @@ -50,10 +50,10 @@ class SimLikeComponentsModel { } /** - * @param {number} dt - delta time, in seconds + * @param dt - delta time, in seconds * @public */ - step( dt ) { + step( dt: number ) { if ( this.ballsMovingProperty.value ) { this.boxOfBalls.step( dt ); } @@ -68,7 +68,6 @@ class SimLikeComponentsModel { this.ballsMovingProperty.reset(); this.resetInProgressProperty.value = false; } - } tambo.register( 'SimLikeComponentsModel', SimLikeComponentsModel );