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

Commit 94bc59e

Browse files
authored
Merge pull request #270 from ckeditor/t/ckeditor5/1341
Fix: There should be no memory leaks when the editor is created and destroyed (see ckeditor/ckeditor5#1341).
2 parents e941872 + 25529a0 commit 94bc59e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/focustracker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ export default class FocusTracker {
9494
}
9595
}
9696

97+
/**
98+
* Destroys the focus tracker by:
99+
* - Disabling all event listeners attached to tracked elements.
100+
* - Removing all tracked elements that were previously added.
101+
*/
102+
destroy() {
103+
this.stopListening();
104+
}
105+
97106
/**
98107
* Stores currently focused element and set {#isFocused} as `true`.
99108
*

tests/focustracker.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,14 @@ describe( 'FocusTracker', () => {
170170
expect( focusTracker.isFocused ).to.false;
171171
} );
172172
} );
173+
174+
describe( 'destroy()', () => {
175+
it( 'should stop listening', () => {
176+
const stopListeningSpy = sinon.spy( focusTracker, 'stopListening' );
177+
178+
focusTracker.destroy();
179+
180+
sinon.assert.calledOnce( stopListeningSpy );
181+
} );
182+
} );
173183
} );

0 commit comments

Comments
 (0)