Skip to content

Commit

Permalink
Assorted Tiny*Property updates and doc improvements, see phetsims/sce…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jun 2, 2020
1 parent 9ac609d commit fea1123
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 7 additions & 0 deletions js/TinyForwardingProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class TinyForwardingProperty extends TinyProperty {
* @param {Property.<*>|null} property - null to "unset" forwarding.
*/
setForwardingProperty( property ) {
// no-op if we are already forwarding to that property OR if we still aren't forwarding
if ( this.forwardingProperty === property ) {
return;
}

// Lazily set this value, it will be added as a listener to any forwardingProperty we have.
this.forwardingListener = this.forwardingListener || ( ( value, oldValue, property ) => {
Expand Down Expand Up @@ -77,6 +81,7 @@ class TinyForwardingProperty extends TinyProperty {
return this.forwardingProperty.value;
}
else {
// NOTE: This is not using super here, since we don't want to call onAccessAttempt twice()
return this._value;
}
}
Expand Down Expand Up @@ -110,6 +115,8 @@ class TinyForwardingProperty extends TinyProperty {
* @param {*} oldValue
*/
notifyListeners( oldValue ) {
// NOTE: This is overridden to use this.get(), since we need to hook up forwarding, and onAccessAttept being called
// is NOT a problem here due to the more specific usage.
this.emit( this.get(), oldValue, this );
}

Expand Down
1 change: 1 addition & 0 deletions js/TinyProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class TinyProperty extends TinyEmitter {
* @param {*} oldValue
*/
notifyListeners( oldValue ) {
// We use this._value here for performance, AND to avoid calling onAccessAttempt unnecessarily.
this.emit( this._value, oldValue, this );
}

Expand Down
8 changes: 0 additions & 8 deletions js/TinyStaticProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import TinyProperty from './TinyProperty.js';
import axon from './axon.js';

class TinyStaticProperty extends TinyProperty {
/**
* @param {*} value - The initial value of the property
* @param {Object} [options] - options
*/
constructor( value, options ) {
super( value, options );
}

/**
* Don't set the value of a TinyStaticProperty!
* @public
Expand Down

0 comments on commit fea1123

Please sign in to comment.