Skip to content

TinyForwardingProperty

Overview

A lightweight version of Property (that satisfies some of the interface), meant for high-performance applications where validation, phet-io support and other things are not needed. This includes additional logic for conditionally forwarding to/from another Property.

Please note that TinyForwardingProperty exclusively supports settable Properties via its TypeScript implementation. If you want to use a read-only Property as the target, please type cast as settable and use runtime assertions to ensure that the target (or this forwarding Property) are not set. See examples like Node.setVisibleProperty.

@author Sam Reid (PhET Interactive Simulations) @author Michael Kauzmann (PhET Interactive Simulations) @author Jonathan Olson <jonathan.olson@colorado.edu>

Class TinyForwardingProperty

import { TinyForwardingProperty } from 'scenerystack/axon';

Constructor

new TinyForwardingProperty( value : ValueType, targetPropertyInstrumented, onBeforeNotify? : TinyPropertyOnBeforeNotify<ValueType> )

Instance Methods

setValueOrTargetProperty( node : NodeParam, tandemName : string | null, newValueOrTargetProperty : TReadOnlyProperty<ValueType> | ValueType )

API support for setting a Property|ValueType onto the forwarding Property

setTargetProperty( newTargetProperty : TReadOnlyProperty<ValueType> | null, node : NodeParam, tandemName : string | null ) : NodeParam

Sets (or unsets if null is provided) the Property that we use for forwarding changes.

@param newTargetProperty - null to "unset" forwarding. @param node - (For phet-io support only): The container of TinyForwardingProperty which supports updateLinkedElementForProperty() @param tandemName - null if the Property does not support PhET-iO instrumentation @returns the passed in Node, for chaining.

set( value : ValueType ) : this

Sets the value and notifies listeners, unless deferred or disposed. You can also use the es5 getter (property.value) but this means is provided for inner loops or internal code that must be fast. If the value hasn't changed, this is a no-op.

setTargetPropertyInstrumented( targetPropertyInstrumented : boolean, node : NodeType ) : NodeType

Use this to automatically create a forwarded, PhET-iO instrumented Property owned by this TinyForwardingProperty.

getTargetPropertyInstrumented() : boolean

initializePhetio( node : NodeLike, tandemName : string, createProperty : () => TProperty<ValueType> )

@param node - the parent container that supports updateLinkedElementForProperty() @param tandemName @param createProperty - creates an "owned" Property

getTargetProperty() : TReadOnlyProperty<ValueType> | null

Get the target property, if any. Use sparingly! Internal use only.

isSettable() : boolean

A TinyForwardingProperty is settable if the target property is settable.

dispose()

Instance Properties

forwardingListener : PropertyLazyLinkListener<ValueType>

(protected)

Set lazily in setTargetProperty()

Source Code

See the source for TinyForwardingProperty.ts in the axon repository.