import {fromJSON as behaviorItemFromJSON} from './registry'; export function Collection(type) { return class Collection { static type() { return `${type}s`; } constructor() { this[`${type}s`] = []; } count() { return this[`${type}s`].length; } fromJSON(json) { this[`${type}s`] = []; for (const i in json.items) { const item = json.items[i]; this[`${type}s`].push(behaviorItemFromJSON(item.type, item)); } return this; } toJSON() { return { type, items: this[`${type}s`].map((item) => item.toJSON()), }; } }; }