From 2a5df239ca87ee88ff46bde0fcaed6b7177da24b Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Fri, 17 Apr 2020 13:26:07 -0600 Subject: [PATCH] Moving Node.visibleProperty on-change code to a visibileProperty listener, see https://github.com/phetsims/scenery/issues/1046 --- js/nodes/Node.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/js/nodes/Node.js b/js/nodes/Node.js index 10dd984a3..fd9c21d4e 100644 --- a/js/nodes/Node.js +++ b/js/nodes/Node.js @@ -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.} - 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 @@ -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 @@ -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 ); },