Skip to content

Commit

Permalink
Converting DerivedProperty/Multilink to properly parameterized TypeSc…
Browse files Browse the repository at this point in the history
…ript, and usage of IReadOnlyProperty. See phetsims/axon#371
  • Loading branch information
jonathanolson committed Dec 8, 2021
1 parent e0ea315 commit 9f57d68
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/CCKCUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const CCKCUtils = {
* @returns {string}
* @public
*/
createCurrentReadout: function( current: number, blackBoxStudy: boolean ): string {
createCurrentReadout: function( current: number | null, blackBoxStudy: boolean ): string {
if ( CCKCQueryParameters.fullPrecisionAmmeter ) {
return current + '';
}
Expand Down
2 changes: 1 addition & 1 deletion js/view/AmmeterNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AmmeterNode extends Node {
);

const currentReadoutProperty = new DerivedProperty( [ ammeter.currentProperty, ammeterReadoutTypeProperty ],
( ( current: number, ammeterReadoutType: AmmeterReadoutType ) => {
( ( current: number | null, ammeterReadoutType: AmmeterReadoutType ) => {
return CCKCUtils.createCurrentReadout( current, options.blackBoxStudy );
} ) );

Expand Down
7 changes: 4 additions & 3 deletions js/view/CCKCChartNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import CircuitLayerNode from './CircuitLayerNode.js';
import Property from '../../../axon/js/Property.js';
import Bounds2 from '../../../dot/js/Bounds2.js';
import CCKCScreenView from './CCKCScreenView.js';
import IReadOnlyProperty from '../../../axon/js/IReadOnlyProperty.js';

const oneSecondString = circuitConstructionKitCommonStrings.oneSecond;
const timeString = circuitConstructionKitCommonStrings.time;
Expand Down Expand Up @@ -66,8 +67,8 @@ class CCKCChartNode extends Node {
private backgroundDragListener: DragListener | null;
private readonly alignProbesEmitter: Emitter<[]>;
private readonly droppedEmitter: Emitter<[]>;
protected readonly aboveBottomLeft1: DerivedProperty<Vector2>;
protected readonly aboveBottomLeft2: DerivedProperty<Vector2>;
protected readonly aboveBottomLeft1: IReadOnlyProperty<Vector2>;
protected readonly aboveBottomLeft2: IReadOnlyProperty<Vector2>;
private readonly zoomLevelProperty: Property<number>;
protected readonly updatePen: () => void;

Expand Down Expand Up @@ -374,7 +375,7 @@ class CCKCChartNode extends Node {
* @returns {CCKCProbeNode}
* @protected
*/
addProbeNode( color: string, wireColor: string, dx: number, dy: number, connectionProperty: Property<Vector2>, tandem: Tandem ) {
addProbeNode( color: string, wireColor: string, dx: number, dy: number, connectionProperty: IReadOnlyProperty<Vector2>, tandem: Tandem ) {
const probeNode = new CCKCProbeNode( this, this.visibleBoundsProperty, { color: color, tandem: tandem } );

// Add the wire behind the probe.
Expand Down
4 changes: 2 additions & 2 deletions js/view/FixedCircuitElementNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class FixedCircuitElementNode extends CircuitElementNode {
private readonly dragListener: CircuitLayerNodeDragListener | null;
static webglSpriteNodes: Node[];
private readonly updateHighlightVisibility: ( ( circuitElement: CircuitElement | null ) => void ) | null;
private readonly updateFireMultilink: Multilink | null;
private readonly updateFireMultilink: Multilink<[ number, number, boolean ]> | null;

/**
* @param {CCKCScreenView|null} screenView - the main screen view, null for isIcon
Expand Down Expand Up @@ -214,7 +214,7 @@ class FixedCircuitElementNode extends CircuitElementNode {
if ( screenView ) {

// @private {Multilink} - Show fire in batteries and resistors with resistance > 0
this.updateFireMultilink = Property.multilink( [
this.updateFireMultilink = Property.multilink<[ number, number, boolean ]>( [
circuitElement.currentProperty,
( circuitElement instanceof Resistor ) ? circuitElement.resistanceProperty : ONE_AMP_PROPERTY,
screenView.model.isValueDepictionEnabledProperty
Expand Down
2 changes: 1 addition & 1 deletion js/view/VoltmeterNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class VoltmeterNode extends Node {
} );

// Displays the voltage reading
const voltageReadoutProperty = new DerivedProperty( [ voltmeter.voltageProperty ], ( voltage: number ) =>
const voltageReadoutProperty = new DerivedProperty( [ voltmeter.voltageProperty ], ( voltage: number | null ) =>
voltage === null ? MathSymbols.NO_VALUE : CCKCUtils.createVoltageReadout( voltage )
);

Expand Down

0 comments on commit 9f57d68

Please sign in to comment.