Browse Source

Use abstract Model in Canvas

pull/4316/head
Alex Ritter 4 years ago
parent
commit
fda9c38114
  1. 4
      src/abstract/Model.ts
  2. 2
      src/canvas/index.ts
  3. 27
      src/canvas/model/Canvas.ts
  4. 19
      src/editor/index.ts

4
src/abstract/Model.ts

@ -29,4 +29,8 @@ export default class Model<
protected get em() {
return this._module.em;
}
public get em() {
return this._module.em;
}
}

2
src/canvas/index.ts

@ -90,7 +90,7 @@ export default class CanvasModule extends Module<typeof defaults> {
...this.config,
module: this,
};
this.canvas = new Canvas(this.em, this.config);
this.canvas = new Canvas(this);
this.model = this.canvas;
this.startAutoscroll = this.startAutoscroll.bind(this);
this.stopAutoscroll = this.stopAutoscroll.bind(this);

27
src/canvas/model/Canvas.ts

@ -1,11 +1,10 @@
import { Model } from '../../common';
import Backbone from 'backbone';
import { evPageSelect } from '../../pages';
import Frames from './Frames';
import EditorModel from '../../editor/model/Editor';
import Page from '../../pages/model/Page';
import { Model } from "../../abstract";
import { evPageSelect } from "../../pages";
import Frames from "./Frames";
import Page from "../../pages/model/Page";
import CanvasModule from "..";
export default class Canvas extends Backbone.Model {
export default class Canvas extends Model<CanvasModule> {
defaults() {
return {
frame: '',
@ -20,18 +19,16 @@ export default class Canvas extends Backbone.Model {
styles: [],
};
}
em: EditorModel;
config: any;
constructor(em: EditorModel, config: any = {}) {
constructor(module: CanvasModule) {
const { em, config } = module;
const { scripts, styles } = config;
super({scripts, styles});
this.config = config;
this.em = em;
this.listenTo(this, 'change:zoom', this.onZoomChange);
this.listenTo(em, 'change:device', this.updateDevice);
super(module, {scripts, styles});
this.listenTo(this, "change:zoom", this.onZoomChange);
this.listenTo(em, "change:device", this.updateDevice);
this.listenTo(em, evPageSelect, this._pageUpdated);
}
get frames(): Frames {
return this.get('frames');
}

19
src/editor/index.ts

@ -54,14 +54,15 @@
* ## Methods
* @module Editor
*/
import { EventHandler } from 'backbone';
import { isUndefined } from 'underscore';
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';
import { EventHandler } from "backbone";
import { isUndefined } from "underscore";
import { IBaseModule } from "../abstract/Module";
import CanvasModule from "../canvas";
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 implements IBaseModule<typeof defaults> {
constructor(config = {}, opts: any = {}) {
@ -112,7 +113,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
get Panels(): PanelsModule {
return this.em.get('Panels');
}
//@ts-ignore
get Canvas(): CanvasModule {
return this.em.get('Canvas');
}

Loading…
Cancel
Save