From 4e17844c99c87454f1452c6aab0c6ea998213d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 16 Jan 2019 14:24:33 +0100 Subject: [PATCH 1/2] Improve editor destructuring process. --- src/controller/datacontroller.js | 4 +++- src/view/document.js | 9 +++++++++ src/view/editableelement.js | 4 ++++ src/view/view.js | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/controller/datacontroller.js b/src/controller/datacontroller.js index 4eb662be6..95e294152 100644 --- a/src/controller/datacontroller.js +++ b/src/controller/datacontroller.js @@ -351,7 +351,9 @@ export default class DataController { /** * Removes all event listeners set by the DataController. */ - destroy() {} + destroy() { + this.stopListening(); + } /** * Checks if all provided root names are existing editor roots. diff --git a/src/view/document.js b/src/view/document.js index 4993075bc..b2667ddaa 100644 --- a/src/view/document.js +++ b/src/view/document.js @@ -121,6 +121,15 @@ export default class Document { this._postFixers.add( postFixer ); } + /** + * Destroys this instance. Makes sure that all observers are destroyed and listeners removed. + */ + destroy() { + this.roots.map( root => root.destroy() ); + this.roots.clear(); + this.stopListening(); + } + /** * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model. * diff --git a/src/view/editableelement.js b/src/view/editableelement.js index 25a2c6e94..174c610e4 100644 --- a/src/view/editableelement.js +++ b/src/view/editableelement.js @@ -77,6 +77,10 @@ export default class EditableElement extends ContainerElement { } } + destroy() { + this.stopListening(); + } + /** * Returns document associated with the editable. * diff --git a/src/view/view.js b/src/view/view.js index d6d50aec5..9acb09715 100644 --- a/src/view/view.js +++ b/src/view/view.js @@ -398,6 +398,8 @@ export default class View { observer.destroy(); } + this.document.destroy(); + this.stopListening(); } From 7adf235e6c8752f2fc44e972a8c58970c4520cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 16 Jan 2019 15:27:05 +0100 Subject: [PATCH 2/2] Remove redundant collection.clear() calls. --- src/view/document.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/view/document.js b/src/view/document.js index b2667ddaa..653d6d091 100644 --- a/src/view/document.js +++ b/src/view/document.js @@ -126,7 +126,6 @@ export default class Document { */ destroy() { this.roots.map( root => root.destroy() ); - this.roots.clear(); this.stopListening(); }