Browse Source

Fix EditorModule interface

pull/4264/head
Alex Ritter 5 years ago
parent
commit
dbaec11391
  1. 8
      src/abstract/Model.ts
  2. 9
      src/abstract/Module.ts
  3. 21
      src/editor/index.ts

8
src/abstract/Model.ts

@ -1,8 +1,8 @@
import Backbone from "backbone"; import Backbone from "backbone";
import Module from "./Module"; import Module, { IBaseModule } from "./Module";
export default class Model< export default class Model<
TModule extends Module = Module, TModule extends IBaseModule<any> = Module,
T extends Backbone.ObjectHash = any, T extends Backbone.ObjectHash = any,
S = Backbone.ModelSetOptions, S = Backbone.ModelSetOptions,
E = any E = any
@ -21,4 +21,8 @@ export default class Model<
public get module() { public get module() {
return this._module; return this._module;
} }
public get config(): TModule extends IBaseModule<infer C>? C: unknown{
return this._module.config
}
} }

9
src/abstract/Module.ts

@ -1,6 +1,6 @@
import EditorModel from "../editor/model/Editor"; import EditorModel from "../editor/model/Editor";
export interface IModule { export interface IModule<TConfig extends any> extends IBaseModule<TConfig> {
init(cfg: any): void; init(cfg: any): void;
destroy(): void; destroy(): void;
postLoad(key: any): any; postLoad(key: any): any;
@ -10,13 +10,18 @@ export interface IModule {
postRender?(view: any): void; postRender?(view: any): void;
} }
export interface IBaseModule<TConfig extends any> {
em: EditorModel;
config: TConfig;
}
interface ModuleConfig{ interface ModuleConfig{
name: string; name: string;
stylePrefix?: string; stylePrefix?: string;
} }
export default abstract class Module<T extends ModuleConfig = ModuleConfig> export default abstract class Module<T extends ModuleConfig = ModuleConfig>
implements IModule implements IModule<T>
{ {
//conf: CollectionCollectionModuleConfig; //conf: CollectionCollectionModuleConfig;
private _em: EditorModel; private _em: EditorModel;

21
src/editor/index.ts

@ -55,17 +55,18 @@
* @module Editor * @module Editor
*/ */
import { EventHandler } from 'backbone'; import { EventHandler } from 'backbone';
import Module from '../abstract/Module'; import { IBaseModule } from '../abstract/Module';
import cash from '../utils/cash-dom'; import cash from '../utils/cash-dom';
import html from '../utils/html'; import html from '../utils/html';
import defaults from './config/config'; import defaults from './config/config';
import EditorModel from './model/Editor'; import EditorModel from './model/Editor';
import EditorView from './view/EditorView'; import EditorView from './view/EditorView';
export default class EditorModule extends Module<typeof defaults> { export default class EditorModule implements IBaseModule<typeof defaults> {
constructor(config = {}, opts: any = {}) { constructor(config = {}, opts: any = {}) {
var c = { ...defaults, ...config, pStylePrefix: defaults.stylePrefix }; //@ts-ignore
super(new EditorModel(c), c) this.config = { ...defaults, ...config, pStylePrefix: defaults.stylePrefix };
this.em = new EditorModel(this.config);
this.$ = opts.$; this.$ = opts.$;
this.em.init(this); this.em.init(this);
this.editor = this.em; this.editor = this.em;
@ -73,12 +74,8 @@ export default class EditorModule extends Module<typeof defaults> {
editorView?: EditorView; editorView?: EditorView;
editor: EditorModel; editor: EditorModel;
$: cash; $: cash;
em: EditorModel;
/** config: typeof defaults;
* @property {EditorModel}
* @private
*/
//editor = em
modules = []; modules = [];
@ -214,6 +211,10 @@ export default class EditorModule extends Module<typeof defaults> {
return this.em.get("DeviceManager"); return this.em.get("DeviceManager");
} }
getConfig(){
return this.config
}
/** /**
* Returns HTML built inside canvas * Returns HTML built inside canvas
* @param {Object} [opts={}] Options * @param {Object} [opts={}] Options

Loading…
Cancel
Save