1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var Node = /*#__PURE__*/function () {
- function Node() {
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- _classCallCheck(this, Node);
- this.$id = opts.id;
- this.$opts = opts;
- this.$children = [];
- this.$parent = null;
- this.$render = function () {};
- }
- _createClass(Node, [{
- key: "appendChild",
- value: function appendChild(child) {
- this.$children.push(child);
- child.$parent = this;
- }
- }, {
- key: "removeChild",
- value: function removeChild(child) {
- this.$children = this.$children.filter(function (c) {
- return c.$id !== child.$id;
- });
- }
- }]);
- return Node;
- }();
- module.exports = function link() {
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var cb = arguments.length > 1 ? arguments[1] : undefined;
- var node = new Node({
- id: opts.id
- });
- if (typeof cb === 'function') {
- cb(node);
- }
- if (Array.isArray(opts.children)) {
- opts.children.forEach(function (child) {
- node.appendChild(link(child, cb));
- });
- }
- return node;
- };
|