From b4fc53a0e4d62d4c20357c9761b0c65c6f874b60 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Mon, 23 May 2022 16:54:22 -0600 Subject: [PATCH] Move multilink and related methods to Multilink, see https://github.com/phetsims/axon/issues/395 --- js/MeasuringTapeNode.js | 3 ++- js/NumberPicker.js | 7 ++++--- js/ParametricSpringNode.js | 8 ++++---- js/SegmentedBarGraphNode.ts | 4 ++-- js/WireNode.ts | 5 ++--- js/capacitor/CapacitorNode.js | 4 ++-- js/capacitor/EFieldNode.js | 4 ++-- js/capacitor/PlateChargeNode.js | 4 ++-- js/demo/ComponentsScreenView.js | 5 +++-- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/js/MeasuringTapeNode.js b/js/MeasuringTapeNode.js index 0512985a0..28932cf73 100644 --- a/js/MeasuringTapeNode.js +++ b/js/MeasuringTapeNode.js @@ -13,6 +13,7 @@ */ import DerivedProperty from '../../axon/js/DerivedProperty.js'; +import Multilink from '../../axon/js/Multilink.js'; import Property from '../../axon/js/Property.js'; import Bounds2 from '../../dot/js/Bounds2.js'; import Utils from '../../dot/js/Utils.js'; @@ -301,7 +302,7 @@ class MeasuringTapeNode extends Node { // link the positions of base and tip to the measuring tape to the scenery update function. // Must be disposed. - const multilink = Property.multilink( + const multilink = Multilink.multilink( [ this.measuredDistanceProperty, unitsProperty, this.modelViewTransformProperty, this.tipPositionProperty, this.basePositionProperty ], ( measuredDistance, units, modelViewTransform, tipPosition, basePosition ) => { diff --git a/js/NumberPicker.js b/js/NumberPicker.js index a147aa3c3..f91fc8d73 100644 --- a/js/NumberPicker.js +++ b/js/NumberPicker.js @@ -8,6 +8,7 @@ */ import DerivedProperty from '../../axon/js/DerivedProperty.js'; +import Multilink from '../../axon/js/Multilink.js'; import EnumerationDeprecatedProperty from '../../axon/js/EnumerationDeprecatedProperty.js'; import NumberProperty from '../../axon/js/NumberProperty.js'; import Property from '../../axon/js/Property.js'; @@ -401,12 +402,12 @@ class NumberPicker extends AccessibleNumberSpinner( Node, 0 ) { valueProperty.link( valueObserver ); // must be unlinked in dispose // @private update colors for increment components - Property.multilink( [ incrementButtonStateProperty, incrementEnabledProperty ], ( state, enabled ) => { + Multilink.multilink( [ incrementButtonStateProperty, incrementEnabledProperty ], ( state, enabled ) => { updateColors( state, enabled, incrementBackgroundNode, this.incrementArrow, backgroundColors, arrowColors ); } ); // @private update colors for decrement components - Property.multilink( [ decrementButtonStateProperty, decrementEnabledProperty ], ( state, enabled ) => { + Multilink.multilink( [ decrementButtonStateProperty, decrementEnabledProperty ], ( state, enabled ) => { updateColors( state, enabled, decrementBackgroundNode, this.decrementArrow, backgroundColors, arrowColors ); } ); @@ -532,7 +533,7 @@ class NumberPickerInputListener extends FireListener { */ constructor( buttonStateProperty, options ) { super( options ); - Property.multilink( + Multilink.multilink( [ this.isOverProperty, this.isPressedProperty ], ( isOver, isPressed ) => { buttonStateProperty.set( diff --git a/js/ParametricSpringNode.js b/js/ParametricSpringNode.js index 8c0c78d20..c615fb83e 100644 --- a/js/ParametricSpringNode.js +++ b/js/ParametricSpringNode.js @@ -19,7 +19,7 @@ */ import NumberProperty from '../../axon/js/NumberProperty.js'; -import Property from '../../axon/js/Property.js'; +import Multilink from '../../axon/js/Multilink.js'; import Range from '../../dot/js/Range.js'; import Vector2 from '../../dot/js/Vector2.js'; import { Shape } from '../../kite/js/imports.js'; @@ -145,7 +145,7 @@ class ParametricSpringNode extends Node { // Changes to these properties require new points (Vector2) and Shapes, because they change // the number of points and/or how the points are allocated to frontShape and backShape. - Property.multilink( [ + Multilink.multilink( [ this.loopsProperty, this.pointsPerLoopProperty, this.aspectRatioProperty, this.phaseProperty, this.deltaPhaseProperty ], @@ -232,7 +232,7 @@ class ParametricSpringNode extends Node { // Changes to these properties can be accomplished by mutating existing points (Vector2) and Shapes, // because the number of points remains the same, as does their allocation to frontShape and backShape. - Property.lazyMultilink( + Multilink.lazyMultilink( [ this.radiusProperty, this.xScaleProperty ], ( radius, xScale ) => { @@ -269,7 +269,7 @@ class ParametricSpringNode extends Node { } ); // Update the stroke gradients - Property.multilink( + Multilink.multilink( [ this.radiusProperty, this.aspectRatioProperty ], ( radius, aspectRatio ) => { diff --git a/js/SegmentedBarGraphNode.ts b/js/SegmentedBarGraphNode.ts index 3761fb193..246f0b79d 100644 --- a/js/SegmentedBarGraphNode.ts +++ b/js/SegmentedBarGraphNode.ts @@ -8,7 +8,7 @@ */ import Range from '../../dot/js/Range.js'; -import Property from '../../axon/js/Property.js'; +import Multilink from '../../axon/js/Multilink.js'; import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry.js'; import optionize from '../../phet-core/js/optionize.js'; import { IColor, Node, NodeOptions, Rectangle } from '../../scenery/js/imports.js'; @@ -82,7 +82,7 @@ export default class SegmentedBarGraphNode extends Node { } ); // set the visibility and opacity of each of the segments based on the value and range - Property.multilink( [ numberProperty, rangeProperty ], ( value, range ) => { + Multilink.multilink( [ numberProperty, rangeProperty ], ( value, range ) => { assert && assert( range.min <= value && value <= range.max, `numberProperty is out of range: ${value}` ); diff --git a/js/WireNode.ts b/js/WireNode.ts index 278386de8..c973a3a15 100644 --- a/js/WireNode.ts +++ b/js/WireNode.ts @@ -7,8 +7,7 @@ */ import IReadOnlyProperty from '../../axon/js/IReadOnlyProperty.js'; -import { UnknownMultilink } from '../../axon/js/Multilink.js'; -import Property from '../../axon/js/Property.js'; +import Multilink, { UnknownMultilink } from '../../axon/js/Multilink.js'; import Vector2 from '../../dot/js/Vector2.js'; import { Shape } from '../../kite/js/imports.js'; import optionize from '../../phet-core/js/optionize.js'; @@ -38,7 +37,7 @@ export default class WireNode extends Path { super( null, options ); - this.multilink = Property.multilink( [ + this.multilink = Multilink.multilink( [ position1Property, normal1Property, position2Property, normal2Property ], ( position1, normal1, position2, normal2 ) => { this.shape = new Shape() diff --git a/js/capacitor/CapacitorNode.js b/js/capacitor/CapacitorNode.js index ebddfc3d0..234da800d 100644 --- a/js/capacitor/CapacitorNode.js +++ b/js/capacitor/CapacitorNode.js @@ -8,7 +8,7 @@ * @author Andrew Adare (PhET Interactive Simulations) */ -import Property from '../../../axon/js/Property.js'; +import Multilink from '../../../axon/js/Multilink.js'; import validate from '../../../axon/js/validate.js'; import Bounds2 from '../../../dot/js/Bounds2.js'; import { Shape } from '../../../kite/js/imports.js'; @@ -58,7 +58,7 @@ class CapacitorNode extends Node { this.addChild( eFieldNode ); this.addChild( this.topPlateNode ); - const updateGeometry = Property.multilink( [ + const updateGeometry = Multilink.multilink( [ this.capacitor.plateSizeProperty, this.capacitor.plateSeparationProperty ], () => this.updateGeometry() ); diff --git a/js/capacitor/EFieldNode.js b/js/capacitor/EFieldNode.js index 5525e2463..aa6612310 100644 --- a/js/capacitor/EFieldNode.js +++ b/js/capacitor/EFieldNode.js @@ -10,7 +10,7 @@ //modules -import Property from '../../../axon/js/Property.js'; +import Multilink from '../../../axon/js/Multilink.js'; import Dimension2 from '../../../dot/js/Dimension2.js'; import EnumerationDeprecated from '../../../phet-core/js/EnumerationDeprecated.js'; import { CanvasNode } from '../../../scenery/js/imports.js'; @@ -85,7 +85,7 @@ class EFieldNode extends CanvasNode { this.modelViewTransform = modelViewTransform; this.maxEffectiveEField = maxEffectiveEField; - Property.multilink( [ + Multilink.multilink( [ capacitor.plateSizeProperty, capacitor.plateSeparationProperty, capacitor.plateVoltageProperty diff --git a/js/capacitor/PlateChargeNode.js b/js/capacitor/PlateChargeNode.js index 78f33be34..2f6ecd1d5 100644 --- a/js/capacitor/PlateChargeNode.js +++ b/js/capacitor/PlateChargeNode.js @@ -13,7 +13,7 @@ * @author Andrew Adare (PhET Interactive Simulations) */ -import Property from '../../../axon/js/Property.js'; +import Multilink from '../../../axon/js/Multilink.js'; import validate from '../../../axon/js/validate.js'; import Dimension2 from '../../../dot/js/Dimension2.js'; import Range from '../../../dot/js/Range.js'; @@ -77,7 +77,7 @@ class PlateChargeNode extends CanvasNode { this.addChild( this.parentNode ); // No disposal required because the capacitor exists for the life of the sim - Property.multilink( [ + Multilink.multilink( [ capacitor.plateSizeProperty, capacitor.plateChargeProperty ], () => self.isVisible() && self.invalidatePaint() diff --git a/js/demo/ComponentsScreenView.js b/js/demo/ComponentsScreenView.js index abfca61e9..82349ffd5 100644 --- a/js/demo/ComponentsScreenView.js +++ b/js/demo/ComponentsScreenView.js @@ -10,6 +10,7 @@ */ import BooleanProperty from '../../../axon/js/BooleanProperty.js'; +import Multilink from '../../../axon/js/Multilink.js'; import DerivedProperty from '../../../axon/js/DerivedProperty.js'; import Emitter from '../../../axon/js/Emitter.js'; import EnumerationProperty from '../../../axon/js/EnumerationProperty.js'; @@ -670,7 +671,7 @@ function demoProbeNode( layoutBounds ) { const redProperty = new Property( color.red ); const greenProperty = new Property( color.green ); const blueProperty = new Property( color.blue ); - Property.multilink( [ redProperty, greenProperty, blueProperty ], + Multilink.multilink( [ redProperty, greenProperty, blueProperty ], ( r, g, b ) => { colorProperty.value = new Color( r, g, b ); } ); @@ -697,7 +698,7 @@ function demoProbeNode( layoutBounds ) { demoParent.addChild( radioButtonGroup ); // When the model properties change, update the sensor node - Property.multilink( [ + Multilink.multilink( [ colorProperty, radiusProperty, innerRadiusProperty,