mirror of https://github.com/artf/grapesjs.git
3 changed files with 46 additions and 52 deletions
@ -1,50 +0,0 @@ |
|||
import { expectation } from 'sinon'; |
|||
import { bindAll } from 'underscore'; |
|||
import { Collection } from '../../common'; |
|||
import Frame from './Frame'; |
|||
|
|||
export default class Frames extends Collection { |
|||
constructor(models, config = {}) { |
|||
super(models); |
|||
bindAll(this, 'itemLoaded'); |
|||
this.config = config; |
|||
this.on('reset', this.onReset); |
|||
this.on('remove', this.onRemove); |
|||
} |
|||
page; |
|||
|
|||
onReset(m, opts = {}) { |
|||
const prev = opts.previousModels || []; |
|||
prev.map(p => this.onRemove(p)); |
|||
} |
|||
|
|||
onRemove(removed) { |
|||
removed && removed.onRemove(); |
|||
} |
|||
|
|||
itemLoaded() { |
|||
this.loadedItems++; |
|||
|
|||
if (this.loadedItems >= this.itemsToLoad) { |
|||
this.trigger('loaded:all'); |
|||
this.listenToLoadItems(0); |
|||
} |
|||
} |
|||
|
|||
listenToLoad() { |
|||
this.loadedItems = 0; |
|||
this.itemsToLoad = this.length; |
|||
this.listenToLoadItems(1); |
|||
} |
|||
|
|||
listenToLoadItems(on) { |
|||
this.forEach(item => item[on ? 'on' : 'off']('loaded', this.itemLoaded)); |
|||
} |
|||
|
|||
/*add(m, o = {}) { |
|||
const { config } = this; |
|||
return Collection.prototype.add.call(this, m, { ...o, config }); |
|||
}*/ |
|||
} |
|||
|
|||
Frames.prototype.model = Frame; |
|||
@ -0,0 +1,45 @@ |
|||
import { bindAll } from "underscore"; |
|||
import { Collection } from "../../common"; |
|||
import Page from "../../pages/model/Page"; |
|||
import Frame from "./Frame"; |
|||
|
|||
export default class Frames extends Collection<Frame> { |
|||
loadedItems = 0; |
|||
itemsToLoad = 0; |
|||
page?: Page; |
|||
|
|||
constructor(models?: Frame[]) { |
|||
super(models); |
|||
bindAll(this, "itemLoaded"); |
|||
this.on("reset", this.onReset); |
|||
this.on("remove", this.onRemove); |
|||
} |
|||
|
|||
onReset(m: Frame, opts?: { previousModels?: Frame[] }) { |
|||
const prev = opts?.previousModels || []; |
|||
prev.map((p) => this.onRemove(p)); |
|||
} |
|||
|
|||
onRemove(removed?: Frame) { |
|||
removed?.onRemove(); |
|||
} |
|||
|
|||
itemLoaded() { |
|||
this.loadedItems++; |
|||
|
|||
if (this.loadedItems >= this.itemsToLoad) { |
|||
this.trigger("loaded:all"); |
|||
this.listenToLoadItems(false); |
|||
} |
|||
} |
|||
|
|||
listenToLoad() { |
|||
this.loadedItems = 0; |
|||
this.itemsToLoad = this.length; |
|||
this.listenToLoadItems(true); |
|||
} |
|||
|
|||
listenToLoadItems(on: boolean) { |
|||
this.forEach((item) => item[on ? "on" : "off"]("loaded", this.itemLoaded)); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue