Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #270 from ckeditor/t/ckeditor5/1341
Browse files Browse the repository at this point in the history
Fix: There should be no memory leaks when the editor is created and destroyed (see ckeditor/ckeditor5#1341).
  • Loading branch information
oleq authored Jan 22, 2019
2 parents e941872 + 25529a0 commit 94bc59e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/focustracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ export default class FocusTracker {
}
}

/**
* Destroys the focus tracker by:
* - Disabling all event listeners attached to tracked elements.
* - Removing all tracked elements that were previously added.
*/
destroy() {
this.stopListening();
}

/**
* Stores currently focused element and set {#isFocused} as `true`.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/focustracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,14 @@ describe( 'FocusTracker', () => {
expect( focusTracker.isFocused ).to.false;
} );
} );

describe( 'destroy()', () => {
it( 'should stop listening', () => {
const stopListeningSpy = sinon.spy( focusTracker, 'stopListening' );

focusTracker.destroy();

sinon.assert.calledOnce( stopListeningSpy );
} );
} );
} );

0 comments on commit 94bc59e

Please sign in to comment.