Skip to content

Commit

Permalink
Moving Node.visibleProperty on-change code to a visibileProperty list…
Browse files Browse the repository at this point in the history
…ener, see #1046
  • Loading branch information
jonathanolson committed Apr 17, 2020
1 parent b638fff commit 2a5df23
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions js/nodes/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ function Node( options ) {
// Visible nodes by default will not be pickable either.
// NOTE: This is fired synchronously when the visibility of the Node is toggled
this.visibleProperty = new TinyProperty( DEFAULT_OPTIONS.visible );
this.visibleProperty.lazyLink( this.onVisiblePropertyChange.bind( this ) );

// @public {TinyProperty.<number>} - Opacity, in the range from 0 (fully transparent) to 1 (fully opaque).
// NOTE: This is fired synchronously when the opacity of the Node is toggled
Expand Down Expand Up @@ -3117,6 +3118,29 @@ inherit( PhetioObject, Node, extend( {
},
get id() { return this.getId(); },

/**
* Called when our visibility Property changes values.
* @private
*
* @param {boolean} visible
*/
onVisiblePropertyChange: function( visible ) {
// changing visibility can affect pickability pruning, which affects mouse/touch bounds
this._picker.onVisibilityChange();

if ( assertSlow ) { this._picker.audit(); }

// Defined in ParallelDOM.js
this._accessibleDisplaysInfo.onVisibilityChange( visible );

for ( let i = 0; i < this._parents.length; i++ ) {
const parent = this._parents[ i ];
if ( parent._excludeInvisibleChildrenFromBounds ) {
parent.invalidateChildBounds();
}
}
},

/**
* Sets whether this node is visible.
* @public
Expand All @@ -3127,26 +3151,8 @@ inherit( PhetioObject, Node, extend( {
setVisible: function( visible ) {
assert && assert( typeof visible === 'boolean', 'Node visibility should be a boolean value' );

if ( visible !== this.visibleProperty.value ) {
this.visibleProperty.setPropertyValue( visible );
// this.visibleProperty.value = visible; // TODO: yikes!

// changing visibility can affect pickability pruning, which affects mouse/touch bounds
this._picker.onVisibilityChange();
if ( assertSlow ) { this._picker.audit(); }

// Defined in ParallelDOM.js
this._accessibleDisplaysInfo.onVisibilityChange( visible );

this.visibleProperty.notifyListeners( !visible );
this.visibleProperty.set( visible );

for ( let i = 0; i < this._parents.length; i++ ) {
const parent = this._parents[ i ];
if ( parent._excludeInvisibleChildrenFromBounds ) {
parent.invalidateChildBounds();
}
}
}
return this;
},
set visible( value ) { this.setVisible( value ); },
Expand Down

0 comments on commit 2a5df23

Please sign in to comment.