Skip to content

Commit

Permalink
clear dynamic element containers based on isStateInScope, #193
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 24, 2020
1 parent 9810b19 commit b383824
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions js/PhetioDynamicElementContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,12 @@ class PhetioDynamicElementContainer extends PhetioObject {
const phetioStateEngine = phet.phetio.phetioEngine.phetioStateEngine;

// On state start, clear out the container and set to defer notifications.
phetioStateEngine.onBeforeStateSetEmitter.addListener( phetioIDsToSet => {
for ( let i = 0; i < phetioIDsToSet.length; i++ ) {
const phetioID = phetioIDsToSet[ i ];
if ( phetioID.startsWith( this.tandem.phetioID ) ) {

// specify that this is from state setting
this.clear( { fromStateSetting: true } );
this.setNotificationsDeferred( true );
return;
}
phetioStateEngine.onBeforeStateSetEmitter.addListener( isInStateScope => {

// Only clear if this PhetioDynamicElementContainer is in scope of the state to be set
if ( isInStateScope( this.tandem ) ) {
this.clear( { fromStateSetting: true } );
this.setNotificationsDeferred( true );
}
} );

Expand Down

0 comments on commit b383824

Please sign in to comment.