processRelation.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5. var Node = /*#__PURE__*/function () {
  6. function Node() {
  7. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  8. _classCallCheck(this, Node);
  9. this.$id = opts.id;
  10. this.$opts = opts;
  11. this.$children = [];
  12. this.$parent = null;
  13. this.$render = function () {};
  14. }
  15. _createClass(Node, [{
  16. key: "appendChild",
  17. value: function appendChild(child) {
  18. this.$children.push(child);
  19. child.$parent = this;
  20. }
  21. }, {
  22. key: "removeChild",
  23. value: function removeChild(child) {
  24. this.$children = this.$children.filter(function (c) {
  25. return c.$id !== child.$id;
  26. });
  27. }
  28. }]);
  29. return Node;
  30. }();
  31. module.exports = function link() {
  32. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33. var cb = arguments.length > 1 ? arguments[1] : undefined;
  34. var node = new Node({
  35. id: opts.id
  36. });
  37. if (typeof cb === 'function') {
  38. cb(node);
  39. }
  40. if (Array.isArray(opts.children)) {
  41. opts.children.forEach(function (child) {
  42. node.appendChild(link(child, cb));
  43. });
  44. }
  45. return node;
  46. };