Browse Source

Add Page class

pull/3563/head
Artur Arseniev 5 years ago
parent
commit
386a4ce7be
  1. 24
      src/pages/model/Page.js

24
src/pages/model/Page.js

@ -2,11 +2,13 @@ import { Model } from 'backbone';
import { result, forEach } from 'underscore'; import { result, forEach } from 'underscore';
import Frames from 'canvas/model/Frames'; import Frames from 'canvas/model/Frames';
export default Model.extend({ export default class Page extends Model {
defaults: () => ({ defaults() {
frames: [], return {
_undo: true frames: [],
}), _undo: true
};
}
initialize(props, opts = {}) { initialize(props, opts = {}) {
const { config = {} } = opts; const { config = {} } = opts;
@ -24,24 +26,24 @@ export default Model.extend({
this.set('frames', frames); this.set('frames', frames);
const um = em && em.get('UndoManager'); const um = em && em.get('UndoManager');
um && um.add(frames); um && um.add(frames);
}, }
onRemove() { onRemove() {
this.get('frames').reset(); this.get('frames').reset();
}, }
getFrames() { getFrames() {
return this.get('frames'); return this.get('frames');
}, }
getMainFrame() { getMainFrame() {
return this.getFrames().at(0); return this.getFrames().at(0);
}, }
getMainComponent() { getMainComponent() {
const frame = this.getMainFrame(); const frame = this.getMainFrame();
return frame && frame.getComponent(); return frame && frame.getComponent();
}, }
toJSON(opts = {}) { toJSON(opts = {}) {
const obj = Model.prototype.toJSON.call(this, opts); const obj = Model.prototype.toJSON.call(this, opts);
@ -58,4 +60,4 @@ export default Model.extend({
return obj; return obj;
} }
}); }

Loading…
Cancel
Save