Explorar el Código

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).
Aleksander Nowodzinski hace 6 años
padre
commit
bd98a3a14b

+ 9 - 0
packages/ckeditor5-utils/src/focustracker.js

@@ -95,6 +95,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`.
 	 *
 	 * @private

+ 10 - 0
packages/ckeditor5-utils/tests/focustracker.js

@@ -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 );
+		} );
+	} );
 } );