Browse Source

Fix EditorModule interface

pull/4264/head
Alex Ritter 4 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 Module from "./Module";
import Module, { IBaseModule } from "./Module";
export default class Model<
TModule extends Module = Module,
TModule extends IBaseModule<any> = Module,
T extends Backbone.ObjectHash = any,
S = Backbone.ModelSetOptions,
E = any
@ -21,4 +21,8 @@ export default class Model<
public get 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";
export interface IModule {
export interface IModule<TConfig extends any> extends IBaseModule<TConfig> {
init(cfg: any): void;
destroy(): void;
postLoad(key: any): any;
@ -10,13 +10,18 @@ export interface IModule {
postRender?(view: any): void;
}
export interface IBaseModule<TConfig extends any> {
em: EditorModel;
config: TConfig;
}
interface ModuleConfig{
name: string;
stylePrefix?: string;
}
export default abstract class Module<T extends ModuleConfig = ModuleConfig>
implements IModule
implements IModule<T>
{
//conf: CollectionCollectionModuleConfig;
private _em: EditorModel;

21
src/editor/index.ts

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

Loading…
Cancel
Save