From 267901fdd9c548d8d4b44e960eae7d41bc5364d9 Mon Sep 17 00:00:00 2001 From: Alex Ritter Date: Wed, 13 Apr 2022 22:08:05 +0200 Subject: [PATCH] Remove init function from EditorModule --- src/canvas/index.js | 1 - src/editor/index.js | 35 ++++++++++-------------------- src/index.js | 2 +- test/specs/block_manager/index.js | 8 +++---- test/specs/device_manager/index.js | 12 +++++----- test/specs/editor/index.js | 8 +------ test/specs/i18n/index.js | 2 +- test/specs/keymaps/index.js | 2 +- 8 files changed, 25 insertions(+), 45 deletions(-) diff --git a/src/canvas/index.js b/src/canvas/index.js index be6896f2f..41af819f9 100644 --- a/src/canvas/index.js +++ b/src/canvas/index.js @@ -267,7 +267,6 @@ export default class CanvasModule { model: this.canvas, config: this.c, }); - console.log(this.canvas); return this.canvasView.render().el; } diff --git a/src/editor/index.js b/src/editor/index.js index 154705a52..cb0d21340 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -62,31 +62,11 @@ import EditorView from './view/EditorView'; export default class EditorModule { constructor(config = {}, opts = {}) { this.$ = opts.$; - this.c = { - ...defaults, - ...config, - }; + this.c = { ...defaults, ...config }; this.c.pStylePrefix = this.c.stylePrefix; this.em = new EditorModel(this.c); + this.em.init(this); this.editor = this.em; - } - editorView; - - /** - * @property {EditorModel} - * @private - */ - //editor = em - - modules = []; - - /** - * Initialize editor model - * @return {this} - * @private - */ - init(opts = {}) { - this.em.init(this, { ...this.c, ...opts }); this.modules = [ 'I18n', @@ -131,9 +111,16 @@ export default class EditorModule { this[prop] = this.em.get(prop); } }); - - return this; } + editorView; + + /** + * @property {EditorModel} + * @private + */ + //editor = em + + modules = []; /** * Returns configuration object diff --git a/src/index.js b/src/index.js index 4b92d2cbb..c8522ffd3 100644 --- a/src/index.js +++ b/src/index.js @@ -52,7 +52,7 @@ export default { if (!els && !headless) throw new Error("'container' is required"); config = { ...defaultConfig, ...config, grapesjs: this }; config.el = !headless && (isElement(els) ? els : document.querySelector(els)); - const editor = new Editor(config, { $ }).init(); + const editor = new Editor(config, { $ }); const em = editor.getModel(); // Load plugins diff --git a/test/specs/block_manager/index.js b/test/specs/block_manager/index.js index 8fe0c09c7..5dc14e097 100644 --- a/test/specs/block_manager/index.js +++ b/test/specs/block_manager/index.js @@ -10,14 +10,14 @@ describe('BlockManager', () => { beforeEach(() => { editor = new Editor({ blockManager: { - blocks: [] - } - }).init(); + blocks: [], + }, + }); idTest = 'h1-block'; optsTest = { label: 'Heading', - content: '

Test

' + content: '

Test

', }; obj = editor.Blocks; diff --git a/test/specs/device_manager/index.js b/test/specs/device_manager/index.js index f4a719afb..930109207 100644 --- a/test/specs/device_manager/index.js +++ b/test/specs/device_manager/index.js @@ -13,9 +13,9 @@ describe('DeviceManager', () => { testWidthDevice = '100px'; editor = new Editor({ deviceManager: { - devices: [] - } - }).init(); + devices: [], + }, + }); em = editor.getModel(); obj = editor.Devices; }); @@ -64,7 +64,7 @@ describe('DeviceManager', () => { test('Add device with props', () => { const model = obj.add({ name: testNameDevice, - width: testWidthDevice + width: testWidthDevice, }); expect(model.get('id')).toEqual(testNameDevice); expect(model.get('name')).toEqual(testNameDevice); @@ -73,7 +73,7 @@ describe('DeviceManager', () => { test('Add device without id and name', () => { const model = obj.add({ - width: testWidthDevice + width: testWidthDevice, }); expect(model.get('name')).toEqual(''); expect(model.get('width')).toEqual(testWidthDevice); @@ -97,7 +97,7 @@ describe('DeviceManager', () => { test('Get device by name with different id', () => { const model = obj.add({ id: 'device', - name: testNameDevice + name: testNameDevice, }); const model2 = obj.get(testNameDevice); expect(model).toBe(model2); diff --git a/test/specs/editor/index.js b/test/specs/editor/index.js index 5c54fe99e..403480d3d 100644 --- a/test/specs/editor/index.js +++ b/test/specs/editor/index.js @@ -8,7 +8,6 @@ describe('Editor', () => { beforeEach(() => { editor = new Editor(); - editor.init(); editor.getModel().loadOnStart(); }); @@ -99,12 +98,7 @@ describe('Editor', () => { `); expect(umStack.length).toBe(1); // UM counts first children expect(keys(all).length).toBe(5 + initComps); - wrapper - .components() - .at(0) - .components() - .at(0) - .remove(); // Remove 1 component + wrapper.components().at(0).components().at(0).remove(); // Remove 1 component expect(umStack.length).toBe(2); expect(keys(all).length).toBe(3 + initComps); diff --git a/test/specs/i18n/index.js b/test/specs/i18n/index.js index ee536dca0..50357b1e4 100644 --- a/test/specs/i18n/index.js +++ b/test/specs/i18n/index.js @@ -4,7 +4,7 @@ import Editor from 'editor'; describe('I18n', () => { describe('Main', () => { let obj; - let editor = new Editor().init(); + let editor = new Editor(); let em = editor.getModel(); beforeEach(() => { diff --git a/test/specs/keymaps/index.js b/test/specs/keymaps/index.js index 05fc7afec..968c81d79 100644 --- a/test/specs/keymaps/index.js +++ b/test/specs/keymaps/index.js @@ -7,7 +7,7 @@ describe('Keymaps', () => { let editor; beforeEach(() => { - editor = new Editor({ keymaps: { defaults: [] } }).init(); + editor = new Editor({ keymaps: { defaults: [] } }); em = editor.getModel(); em.loadOnStart(); obj = editor.Keymaps;