Skip to content

Commit

Permalink
Generalize property declarations, see: #82
Browse files Browse the repository at this point in the history
marlitas committed Jul 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 679a55f commit 16be252
Showing 5 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions js/intro/model/IntroModel.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ export default class IntroModel extends MeanShareAndBalanceModel {
public readonly meanVisibleProperty: Property<boolean>;
public readonly tickMarksVisibleProperty: Property<boolean>;

public readonly numberOfCupsProperty: NumberProperty;
public readonly numberOfCupsProperty: Property<number>;
public readonly meanPredictionProperty: Property<number>;
public readonly meanProperty: IReadOnlyProperty<number>;

@@ -321,7 +321,7 @@ export default class IntroModel extends MeanShareAndBalanceModel {
* @param range - the allowed waterLevelProperty range in each cup
* @param waterLevelProperty - The property tracking the water level in each cup's model.
*/
private static constrainDelta( delta: number, range: Range, waterLevelProperty: NumberProperty ): number {
private static constrainDelta( delta: number, range: Range, waterLevelProperty: Property<number> ): number {
const newWaterLevel = waterLevelProperty.value + delta;
const constrainedWaterLevel = range.constrainValue( newWaterLevel );
return constrainedWaterLevel - waterLevelProperty.value;
@@ -334,7 +334,7 @@ export default class IntroModel extends MeanShareAndBalanceModel {
* @param waterLevel - The current waterLevel
* @param oldWaterLevel - The previous waterLevel
*/
public changeWaterLevel( cup3DModel: WaterCup, adapterProperty: NumberProperty, waterLevel: number, oldWaterLevel: number ): void {
public changeWaterLevel( cup3DModel: WaterCup, adapterProperty: Property<number>, waterLevel: number, oldWaterLevel: number ): void {

// During reset we only want to specify the exact values of the adapterProperty and waterLevelProperties.
// We do not want to compensate with waterLevel deltas.
2 changes: 1 addition & 1 deletion js/intro/model/WaterCup.ts
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ export type WaterCupModelOptions =
export default class WaterCup extends PhetioObject {

// Whether the cup is enabled in view and data calculations
public readonly isActiveProperty: BooleanProperty;
public readonly isActiveProperty: Property<boolean>;

// The x and y positions for the cup in the view.
public readonly position: Vector2;
6 changes: 2 additions & 4 deletions js/intro/view/PredictMeanSlider.ts
Original file line number Diff line number Diff line change
@@ -15,13 +15,11 @@ import meanShareAndBalance from '../../meanShareAndBalance.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import Range from '../../../../dot/js/Range.js';
import optionize from '../../../../phet-core/js/optionize.js';
import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import AccessibleSlider, { AccessibleSliderOptions } from '../../../../sun/js/accessibility/AccessibleSlider.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import ShadedSphereNode from '../../../../scenery-phet/js/ShadedSphereNode.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import WaterCup from '../model/WaterCup.js';
import Property from '../../../../axon/js/Property.js';

@@ -34,7 +32,7 @@ export default class PredictMeanSlider extends AccessibleSlider( Node, 0 ) {
private readonly predictMeanHandle: Circle;
private readonly dragListener: DragListener;

public constructor( meanPredictionProperty: Property<number>, dragRange: Range, numberOfCupsProperty: NumberProperty,
public constructor( meanPredictionProperty: Property<number>, dragRange: Range, numberOfCupsProperty: Property<number>,
getActive2DCups: () => Array<WaterCup>, modelViewTransform: ModelViewTransform2, providedOptions: PredictMeanNodeOptions ) {

const options = optionize<PredictMeanNodeOptions, SelfOptions, ParentOptions>()( {
4 changes: 2 additions & 2 deletions js/intro/view/WaterCup3DNode.ts
Original file line number Diff line number Diff line change
@@ -29,12 +29,12 @@ type WaterCup3DNodeOptions = SelfOptions & StrictOmit<NodeOptions, 'y' | 'x' | '
export default class WaterCup3DNode extends Node {
private readonly waterLevelTriangle: WaterLevelTriangleNode;
private readonly waterCup: WaterCup;
private readonly adapterProperty: NumberProperty;
private readonly adapterProperty: Property<number>;
private readonly tickMarksVisibleProperty: Property<boolean>;
private readonly showTickMarksLink: ( isShowingTickMarks: boolean ) => void;

public constructor( tickMarksVisibleProperty: Property<boolean>,
changeWaterLevel: ( cup3DModel: WaterCup, adapterProperty: NumberProperty, waterLevel: number, oldWaterLevel: number ) => void,
changeWaterLevel: ( cup3DModel: WaterCup, adapterProperty: Property<number>, waterLevel: number, oldWaterLevel: number ) => void,
waterCup: WaterCup, modelViewTransform: ModelViewTransform2,
providedOptions?: WaterCup3DNodeOptions ) {

3 changes: 1 addition & 2 deletions js/intro/view/WaterLevelTriangleNode.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import meanShareAndBalance from '../../meanShareAndBalance.js';
import { Node, NodeOptions } from '../../../../scenery/js/imports.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import VSlider from '../../../../sun/js/VSlider.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import Range from '../../../../dot/js/Range.js';
@@ -29,7 +28,7 @@ export default class WaterLevelTriangleNode extends Node {

//REVIEW why is waterLevelProperty not Property<number>, as in VSlider?
//REVIEW why is enabledRangeProperty not IReadOnlyProperty<Range>, as in VSlider trait AccessibleValueHandler?
public constructor( waterLevelProperty: NumberProperty, enabledRangeProperty: Property<Range>, height: number,
public constructor( waterLevelProperty: Property<number>, enabledRangeProperty: Property<Range>, height: number,
providedOptions?: WaterLevelTriangleNodeOptions ) {
const options = optionize<WaterLevelTriangleNodeOptions, SelfOptions, NodeOptions>()( {
cursor: 'pointer'

0 comments on commit 16be252

Please sign in to comment.