Skip to content

Commit

Permalink
dispose accessible peers, see phetsims/scenery-phet#226
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Dec 13, 2016
1 parent 4405589 commit 10a68a2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions js/accessibility/AccessiblePeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,29 @@ define( function( require ) {
this.disposed = false;

// @private - listener for the focus event, to be disposed
self.focusEventListener = function( event ) {
var focusEventListener = function( event ) {
if ( event.target === self.domElement ) {
Display.focus = {
display: accessibleInstance.display,
trail: accessibleInstance.trail
};
}
};
this.domElement.addEventListener( 'focus', self.focusEventListener );
this.domElement.addEventListener( 'focus', focusEventListener );

// @private - listener for the blur event, to be disposed
self.blurEventListener = function( event ) {
var blurEventListener = function( event ) {
if ( event.target === self.domElement ) {
Display.focus = null;
}
};
this.domElement.addEventListener( 'blur', self.blurEventListener );
this.domElement.addEventListener( 'blur', blurEventListener );

// make AccessiblePeer eligible for garabage collection
this.disposeAccessiblePeer = function() {
self.domElement.removeEventListener( 'blur', blurEventListener );
self.domElement.removeEventListener( 'focus', focusEventListener );
};

return this;
},
Expand Down Expand Up @@ -128,9 +134,7 @@ define( function( require ) {

dispose: function() {
this.disposed = true;

this.domElement.removeEventListener( 'blur', this.blurEventListener );
this.domElement.removeEventListener( 'focus', this.focusEventListener );
this.disposeAccessiblePeer();

// for now
this.freeToPool && this.freeToPool();
Expand Down

0 comments on commit 10a68a2

Please sign in to comment.