TinyProperty¶
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 directly extends TinyEmitter in order to save memory.
@author Sam Reid (PhET Interactive Simulations) @author Jonathan Olson <jonathan.olson@colorado.edu>
Class TinyProperty¶
Constructor¶
new TinyProperty( value : T, onBeforeNotify? : OptionsAlias<T>['onBeforeNotify'] | null, hasListenerOrderDependencies? : OptionsAlias<T>['hasListenerOrderDependencies'] | null, reentrantNotificationStrategy? : OptionsAlias<T>['reentrantNotificationStrategy'] | null )¶
Instance Methods¶
get() : T¶
Returns the value.
You can also use the es5 getter (property.value) but this means is provided for inner loops or internal code that must be fast.
set( value : T )¶
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.
setPropertyValue( value : T )¶
Sets the value without notifying any listeners. This is a place to override if a subtype performs additional work when setting the value.
equalsValue( value : T ) : boolean¶
(protected)
Returns true if and only if the specified value equals the value of this property. This is used to determine if a Property's value should change and if listeners should be notified. In general, this implementation should not be overridden except to provide more correct "value"s as parameters for the areValuesEqual() function.
areValuesEqual( a : T, b : T ) : boolean¶
Central logic for determining value equality for Property. This determines if a value should change, and if listeners should notify based on set() call.
Determines equality semantics for value comparison, including whether notifications are sent out when the wrapped value changes, and whether onValue() is triggered. See Validation.equalsForValidationStrategy for details and doc on ValueComparisonStrategy
Overriding this function is deprecated, instead provide a custom valueComparisonStrategy.
notifyListeners( oldValue : T )¶
Directly notifies listeners of changes.
link( listener : PropertyLinkListener<T> )¶
Adds listener and calls it immediately. If listener is already registered, this is a no-op. The initial notification provides the current value for newValue and null for oldValue.
lazyLink( listener : PropertyLazyLinkListener<T> )¶
Add an listener to the TinyProperty, without calling it back right away. This is used when you need to register a listener without an immediate callback.
unlink( listener : PropertyListener<T> )¶
Removes a listener. If listener is not registered, this is a no-op.
unlinkAll()¶
Removes all listeners. If no listeners are registered, this is a no-op.
linkAttribute( object : Record<Attr, T>, attributeName : Attr ) : ( value: T ) => void¶
Links an object's named attribute to this TinyProperty. Returns a handle so it can be removed using TinyProperty.unlink(); Example: modelVisibleProperty.linkAttribute(view, 'visible');
NOTE: Duplicated with Property.linkAttribute
isSettable() : boolean¶
Returns true if the value can be set externally, using .value= or set()
dispose()¶
Releases references.
Type TinyPropertyEmitterParameters¶
[ T, T | null, TReadOnlyProperty<T> ]
Type TinyPropertyOnBeforeNotify¶
( ...args: TinyPropertyEmitterParameters<T> ) => void
Source Code¶
See the source for TinyProperty.ts in the axon repository.