Skip to content

Commit

Permalink
Additional tiny emitter/property improvements, see #490
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 9, 2020
1 parent 4a1fe16 commit e93c44d
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 149 deletions.
2 changes: 1 addition & 1 deletion js/accessibility/pdom/PDOMInputTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ QUnit.test( 'focusin/focusout (focus/blur)', assert => {
} );

a.focus();
debugger;

assert.ok( aGotFocus, 'a should have been focused' );
assert.ok( !aLostFocus, 'a should not blur' );

Expand Down
4 changes: 2 additions & 2 deletions js/accessibility/pdom/ParallelDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ const ParallelDOM = {

PDOMTree.accessibleOrderChange( this, oldAccessibleOrder, accessibleOrder );

this.accessibleOrderEmitter.emit();
this.rendererSummaryRefreshEmitter.emit();
}
},
set accessibleOrder( value ) { this.setAccessibleOrder( value ); },
Expand Down Expand Up @@ -2633,7 +2633,7 @@ const ParallelDOM = {
// recompute the heading level for this node if it is using the accessibleHeading API.
this._accessibleHeading && this.computeHeadingLevel();

this.accessibleContentEmitter.emit();
this.rendererSummaryRefreshEmitter.emit();
},

/**
Expand Down
8 changes: 2 additions & 6 deletions js/display/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1441,9 +1441,7 @@ inherit( Object, Instance, {

this.node.opacityProperty.lazyLink( this.markRenderStateDirtyListener );
this.node.clipAreaProperty.lazyLink( this.markRenderStateDirtyListener );
this.node.hintEmitter.addListener( this.markRenderStateDirtyListener );
this.node.rendererBitmaskEmitter.addListener( this.markRenderStateDirtyListener );
this.node.rendererSummaryEmitter.addListener( this.markRenderStateDirtyListener );
this.node.instanceRefreshEmitter.addListener( this.markRenderStateDirtyListener );
}
},

Expand All @@ -1458,9 +1456,7 @@ inherit( Object, Instance, {

this.node.opacityProperty.unlink( this.markRenderStateDirtyListener );
this.node.clipAreaProperty.unlink( this.markRenderStateDirtyListener );
this.node.hintEmitter.removeListener( this.markRenderStateDirtyListener );
this.node.rendererBitmaskEmitter.removeListener( this.markRenderStateDirtyListener );
this.node.rendererSummaryEmitter.removeListener( this.markRenderStateDirtyListener );
this.node.instanceRefreshEmitter.removeListener( this.markRenderStateDirtyListener );
}
},

Expand Down
178 changes: 73 additions & 105 deletions js/nodes/Node.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions js/nodes/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ inherit( Node, Path, {
this._boundsMethod = boundsMethod;
this.invalidatePath();

this.selfBoundsValidEmitter.emit(); // whether our self bounds are valid may have changed
this.rendererSummaryRefreshEmitter.emit(); // whether our self bounds are valid may have changed
}
return this;
},
Expand Down Expand Up @@ -431,7 +431,8 @@ inherit( Node, Path, {
*/
invalidateStroke: function() {
this.invalidatePath();
this.selfBoundsValidEmitter.emit(); // Stroke changing could have changed our self-bounds-validitity (unstroked/etc)

this.rendererSummaryRefreshEmitter.emit(); // Stroke changing could have changed our self-bounds-validitity (unstroked/etc)
},

/**
Expand Down
4 changes: 1 addition & 3 deletions js/nodes/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ function RichText( text, options ) {

Node.call( this );

Node.preventSettersOnProperty( this, 'textProperty' );

// @private {Node} - Normal layout container of lines (separate, so we can clear it easily)
this.lineContainer = new Node( {} );
this.addChild( this.lineContainer );
Expand Down Expand Up @@ -720,7 +718,7 @@ inherit( Node, RichText, {
this.textProperty.setPropertyValue( text );
this.rebuildRichText();

this.textProperty._notifyListeners( oldText );
this.textProperty.notifyListeners( oldText );
}
return this;
},
Expand Down
6 changes: 2 additions & 4 deletions js/nodes/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ function Text( text, options ) {

Node.call( this, options );

Node.preventSettersOnProperty( this, 'textProperty' );

this.invalidateSupportedRenderers(); // takes care of setting up supported renderers
}

Expand Down Expand Up @@ -139,7 +137,7 @@ inherit( Node, Text, {

this.invalidateText();

this.textProperty._notifyListeners( oldText );
this.textProperty.notifyListeners( oldText );
}
return this;
},
Expand Down Expand Up @@ -215,7 +213,7 @@ inherit( Node, Text, {

this.invalidateText();

this.selfBoundsValidEmitter.emit(); // whether our self bounds are valid may have changed
this.rendererSummaryRefreshEmitter.emit(); // whether our self bounds are valid may have changed
}
return this;
},
Expand Down
35 changes: 14 additions & 21 deletions js/util/DisplayedProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ class DisplayedProperty extends BooleanProperty {

// @private {function}
this.updateListener = this.updateValue.bind( this );
this.addedInstancelistener = this.addedInstance.bind( this );
this.removedInstancelistener = this.removedInstance.bind( this );
this.changedInstanceListener = this.changedInstance.bind( this );

node.addedInstanceEmitter.addListener( this.addedInstancelistener );
node.removedInstanceEmitter.addListener( this.removedInstancelistener );
node.changedInstanceEmitter.addListener( this.changedInstanceListener );

// Add any instances the node may already have/
const instances = node.instances;
for ( let i = 0; i < instances.length; i++ ) {
this.addedInstance( instances[ i ] );
this.changedInstance( instances[ i ], true );
}
}

Expand All @@ -58,24 +56,20 @@ class DisplayedProperty extends BooleanProperty {
}

/**
* Adds a listener to one of the node's instances.
* Called when an instance is changed or added (based on the boolean flag).
* @private
*
* @param {Instance} instance
* @param {boolean} added
*/
addedInstance( instance ) {
instance.visibleEmitter.addListener( this.updateListener );
this.updateValue();
}
changedInstance( instance, added ) {
if ( added ) {
instance.visibleEmitter.addListener( this.updateListener );
}
else {
instance.visibleEmitter.removeListener( this.updateListener );
}

/**
* Removes a listener from one of the node's instances.
* @private
*
* @param {Instance} instance
*/
removedInstance( instance ) {
instance.visibleEmitter.removeListener( this.updateListener );
this.updateValue();
}

Expand All @@ -88,11 +82,10 @@ class DisplayedProperty extends BooleanProperty {
// Remove any instances the node may still have
const instances = this.node.instances;
for ( let i = 0; i < instances.length; i++ ) {
this.removedInstance( instances[ i ] );
this.changedInstance( instances[ i ], false );
}

this.node.addedInstanceEmitter.removeListener( this.addedInstancelistener );
this.node.removedInstanceEmitter.removeListener( this.removedInstancelistener );
this.node.changedInstanceEmitter.removeListener( this.changedInstanceListener );

super.dispose();
}
Expand Down
7 changes: 2 additions & 5 deletions js/util/RendererSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ function RendererSummary( node ) {
const listener = this.selfChange.bind( this );
this.node.opacityProperty.lazyLink( listener );
this.node.clipAreaProperty.lazyLink( listener );
this.node.hintEmitter.addListener( listener ); // should fire on things like node.renderer being changed
this.node.selfBoundsValidEmitter.addListener( listener ); // e.g. Text, may change based on boundsMethod
this.node.accessibleContentEmitter.addListener( listener );
this.node.accessibleOrderEmitter.addListener( listener );
this.node.rendererSummaryRefreshEmitter.addListener( listener );
}

scenery.register( 'RendererSummary', RendererSummary );
Expand Down Expand Up @@ -143,7 +140,7 @@ inherit( Object, RendererSummary, {
}
}

this.node.rendererSummaryEmitter.emit();
this.node.instanceRefreshEmitter.emit();
this.node.onSummaryChange( oldSubtreeBitmask, this.bitmask );

const len = this.node._parents.length;
Expand Down

0 comments on commit e93c44d

Please sign in to comment.