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() { protected get em() {
return this._module.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, ...this.config,
module: this, module: this,
}; };
this.canvas = new Canvas(this.em, this.config); this.canvas = new Canvas(this);
this.model = this.canvas; this.model = this.canvas;
this.startAutoscroll = this.startAutoscroll.bind(this); this.startAutoscroll = this.startAutoscroll.bind(this);
this.stopAutoscroll = this.stopAutoscroll.bind(this); this.stopAutoscroll = this.stopAutoscroll.bind(this);

27
src/canvas/model/Canvas.ts

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

19
src/editor/index.ts

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

Loading…
Cancel
Save