Browse Source

Add Pages class

pull/3563/head
Artur Arseniev 5 years ago
parent
commit
be562eea67
  1. 14
      src/pages/model/Pages.js

14
src/pages/model/Pages.js

@ -1,26 +1,26 @@
import { Collection } from 'backbone'; import { Collection } from 'backbone';
import Page from './Page'; import Page from './Page';
export default Collection.extend({ export default class Pages extends Collection {
model: Page,
initialize(models, config = {}) { initialize(models, config = {}) {
this.config = config; this.config = config;
this.on('reset', this.onReset); this.on('reset', this.onReset);
this.on('remove', this.onRemove); this.on('remove', this.onRemove);
}, }
onReset(m, opts = {}) { onReset(m, opts = {}) {
const prev = opts.previousModels || []; const prev = opts.previousModels || [];
prev.map(p => this.onRemove(p)); prev.map(p => this.onRemove(p));
}, }
onRemove(removed) { onRemove(removed) {
removed && removed.onRemove(); removed && removed.onRemove();
}, }
add(m, o = {}) { add(m, o = {}) {
const { config } = this; const { config } = this;
return Collection.prototype.add.call(this, m, { ...o, config }); return Collection.prototype.add.call(this, m, { ...o, config });
} }
}); }
Pages.prototype.model = Page;

Loading…
Cancel
Save