mirror of https://github.com/artf/grapesjs.git
6 changed files with 52 additions and 51 deletions
@ -1,26 +0,0 @@ |
|||
import { Collection } from '../../common'; |
|||
import Page from './Page'; |
|||
|
|||
export default class Pages extends Collection { |
|||
initialize(models, config = {}) { |
|||
this.config = config; |
|||
this.on('reset', this.onReset); |
|||
this.on('remove', this.onRemove); |
|||
} |
|||
|
|||
onReset(m, opts = {}) { |
|||
const prev = opts.previousModels || []; |
|||
prev.map(p => this.onRemove(p)); |
|||
} |
|||
|
|||
onRemove(removed) { |
|||
removed && removed.onRemove(); |
|||
} |
|||
|
|||
add(m, o = {}) { |
|||
const { config } = this; |
|||
return Collection.prototype.add.call(this, m, { ...o, config }); |
|||
} |
|||
} |
|||
|
|||
Pages.prototype.model = Page; |
|||
@ -0,0 +1,18 @@ |
|||
import { Collection } from "../../common"; |
|||
import Page from "./Page"; |
|||
|
|||
export default class Pages extends Collection<Page> { |
|||
constructor(models: any) { |
|||
super(models); |
|||
this.on("reset", this.onReset); |
|||
this.on("remove", this.onRemove); |
|||
} |
|||
|
|||
onReset(m: Page, opts?: { previousModels?: Pages }) { |
|||
opts?.previousModels?.map((p) => this.onRemove(p)); |
|||
} |
|||
|
|||
onRemove(removed?: Page) { |
|||
removed?.onRemove(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue