UNPKG

vasille

Version:

The first Developer eXperience Orientated front-end framework (core library).

49 lines (48 loc) 1.32 kB
import { Fragment } from "../node/node.js"; /** * Repeat node repeats its children * @class RepeatNode * @extends Fragment */ export class RepeatNode extends Fragment { constructor(input, runner, name) { super(input, runner, name); /** * Children node hash * @type {Map} */ this.nodes = new Map(); } createChild(opts, id, item, before) { const _id = id && typeof id === "object" && "id" in id ? id.id : id; const node = new Fragment({}, this.runner, `${_id}`); node.parent = this; this.destroyChild(id, item); if (before) { this.children.add(node); before.insertBefore(node); } else { const lastChild = this.lastChild; if (lastChild) { lastChild.insertAfter(node); } this.children.add(node); } this.lastChild = node; opts.slot && opts.slot(node, item, id); this.nodes.set(id, node); } destroyChild(id, item) { const child = this.nodes.get(id); if (child) { child.remove(); child.destroy(); this.nodes.delete(id); this.children.delete(child); } } destroy() { this.nodes.clear(); } }