Browse Source

Better clear on destroy

fix-leaks-2
Artur Arseniev 7 years ago
parent
commit
1b6d489e3d
  1. 1
      src/commands/view/SelectComponent.js
  2. 7
      src/editor/model/Editor.js
  3. 2
      src/index.js

1
src/commands/view/SelectComponent.js

@ -790,5 +790,6 @@ export default {
this.onOut();
this.toggleToolsEl();
editor && editor.stopCommand('resize');
this.editor = 0;
}
};

7
src/editor/model/Editor.js

@ -686,6 +686,8 @@ export default Backbone.Model.extend({
* Destroy editor
*/
destroyAll() {
const editor = this.getEditor();
const { editors } = this.config.grapesjs;
const {
DomComponents,
CssComposer,
@ -695,6 +697,7 @@ export default Backbone.Model.extend({
Keymaps,
RichTextEditor
} = this.attributes;
this.stopDefault();
DomComponents.clear();
CssComposer.clear();
UndoManager.clear().removeAll();
@ -704,6 +707,10 @@ export default Backbone.Model.extend({
RichTextEditor.destroy();
this.view.remove();
this.stopListening();
this.clear({ silent: true });
this._previousAttributes = {};
this.attributes = {};
editors.splice(editors.indexOf(editor), 1);
$(this.config.el)
.empty()
.attr(this.attrsOrig);

2
src/index.js

@ -47,7 +47,7 @@ export default {
init(config = {}) {
const els = config.container;
if (!els) throw new Error("'container' is required");
config = { ...defaultConfig, ...config };
config = { ...defaultConfig, ...config, grapesjs: this };
config.el = isElement(els) ? els : document.querySelector(els);
const editor = new Editor(config).init();

Loading…
Cancel
Save