UNPKG

d3-view

Version:

View-model d3 plugin for building interactive data-driven web interfaces

47 lines (40 loc) • 869 B
import uid from "../utils/uid"; import ddispatch from "./dispatch"; // // Initialise a model export default function asModel(model, initials, parent, isolated) { var events = new Map(), Child = null; // event handler for any change in the model events.set("", ddispatch()); Object.defineProperties(uid(model), { $events: { get() { return events; } }, parent: { get() { return parent; } }, isolated: { get() { return isolated; } } }); model.$child = $child; model.$update(initials); function $child(o) { if (Child === null) Child = createChildConstructor(model); return new Child(o); } } function createChildConstructor(model) { function Child(initials) { asModel(this, initials, model, false); } Child.prototype = model; return Child; }