From 013c2be9d345659f86fe6a906aea06b9bf6693d5 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 14 Nov 2020 18:21:04 +0100 Subject: [PATCH] Improve Editor destroyAll method --- src/editor/model/Editor.js | 50 ++++++-------------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 544e8de92..3da543aa3 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -750,57 +750,23 @@ export default Backbone.Model.extend({ const { config } = this; const editor = this.getEditor(); const { editors = [] } = config.grapesjs || {}; - const { - DomComponents, - CssComposer, - UndoManager, - Panels, - Canvas, - Keymaps, - RichTextEditor, - LayerManager, - AssetManager, - BlockManager, - CodeManager, - Commands, - DeviceManager, - I18n, - Modal, - Parser, - SelectorManager, - StorageManager, - StyleManager, - TraitManager - } = this.attributes; this.stopDefault(); - DomComponents.destroy(); - CssComposer.destroy(); - UndoManager.destroy(); - Panels.destroy(); - Canvas.destroy(); - Keymaps.destroy(); - RichTextEditor.destroy(); - LayerManager.destroy(); - AssetManager.destroy(); - BlockManager.destroy(); - CodeManager.destroy(); - Commands.destroy(); - DeviceManager.destroy(); - I18n.destroy(); - Modal.destroy(); - Parser.destroy(); - SelectorManager.destroy(); - StorageManager.destroy(); - StyleManager.destroy(); - TraitManager.destroy(); + this.get('modules') + .slice() + .reverse() + .forEach(mod => mod.destroy()); this.view.remove(); this.stopListening(); this.clear({ silent: true }); this.destroyed = 1; + ['config', 'view', '_previousAttributes', '_events', '_listeners'].forEach( + i => (this[i] = {}) + ); editors.splice(editors.indexOf(editor), 1); $(config.el) .empty() .attr(this.attrsOrig); + console.log(this); }, setEditing(value) {