diff --git a/js/common/view/ParticleCanvasProperty.ts b/js/common/view/ParticleCanvasProperty.ts index 9e3116d4..9f083126 100644 --- a/js/common/view/ParticleCanvasProperty.ts +++ b/js/common/view/ParticleCanvasProperty.ts @@ -7,31 +7,19 @@ * @author Chris Malley (PixelZoom, Inc.) */ -import { DerivedProperty1, DerivedPropertyOptions } from '../../../../axon/js/DerivedProperty.js'; +import { DerivedProperty1 } from '../../../../axon/js/DerivedProperty.js'; import Multilink from '../../../../axon/js/Multilink.js'; import Property from '../../../../axon/js/Property.js'; -import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js'; import gasProperties from '../../gasProperties.js'; import Particle from '../model/Particle.js'; import ParticlesNode from './ParticlesNode.js'; -type SelfOptions = EmptySelfOptions; - -type ParticleCanvasPropertyOptions = SelfOptions; - export default class ParticleCanvasProperty extends DerivedProperty1 { - public constructor( particle: Particle, - modelViewTransform: ModelViewTransform2, - providedOptions?: ParticleCanvasPropertyOptions ) { + protected readonly particleCanvasProperty: Property; - const options = optionize>()( { - - // DerivedPropertyOptions - isDisposable: false, - valueType: [ HTMLCanvasElement ] - }, providedOptions ); + public constructor( particle: Particle, modelViewTransform: ModelViewTransform2 ) { // Node.toCanvas takes a callback that doesn't return a value, so use an intermediate Property to // derive the value and act as a proxy for the DerivedProperty dependencies. @@ -47,7 +35,12 @@ export default class ParticleCanvasProperty extends DerivedProperty1 { +export default class DiffusionParticleCanvasProperty extends ParticleCanvasProperty { public constructor( particle: DiffusionParticle, modelViewTransform: ModelViewTransform2, - radiusProperty: TReadOnlyProperty, - providedOptions?: DiffusionParticleCanvasPropertyOptions ) { - - const options = optionize>()( { - - // DerivedPropertyOptions - isDisposable: false, - valueType: [ HTMLCanvasElement ] - }, providedOptions ); + radiusProperty: TReadOnlyProperty ) { - // Node.toCanvas takes a callback that doesn't return a value, so use an intermediate Property to - // derive the value and act as a proxy for the DerivedProperty dependencies. - const particleCanvasProperty = new Property( null ); - Multilink.multilink( [ radiusProperty, particle.colorProperty, particle.highlightColorProperty ], - ( radius, color, highlightColor ) => { - particle.setRadius( radius ); - ParticlesNode.particleToCanvas( particle, modelViewTransform, particleCanvasProperty ); - } ); + super( particle, modelViewTransform ); - super( - [ particleCanvasProperty ], - ( value: HTMLCanvasElement | null ) => { - const canvasElement = value!; - assert && assert( canvasElement ); - return canvasElement; - }, - options ); + radiusProperty.link( radius => { + particle.setRadius( radius ); + ParticlesNode.particleToCanvas( particle, modelViewTransform, this.particleCanvasProperty ); + } ); } }