relation.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.useChildren = exports.useParent = void 0;
  4. function useParent(name, onEffect) {
  5. var _a;
  6. var path = "../" + name + "/index";
  7. return {
  8. relations: (_a = {},
  9. _a[path] = {
  10. type: 'ancestor',
  11. linked: function () {
  12. onEffect && onEffect.call(this);
  13. },
  14. linkChanged: function () {
  15. onEffect && onEffect.call(this);
  16. },
  17. unlinked: function () {
  18. onEffect && onEffect.call(this);
  19. },
  20. },
  21. _a),
  22. mixin: Behavior({
  23. created: function () {
  24. var _this = this;
  25. Object.defineProperty(this, 'parent', {
  26. get: function () { return _this.getRelationNodes(path)[0]; },
  27. });
  28. Object.defineProperty(this, 'index', {
  29. // @ts-ignore
  30. get: function () { var _a, _b; return (_b = (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.indexOf(_this); },
  31. });
  32. },
  33. }),
  34. };
  35. }
  36. exports.useParent = useParent;
  37. function useChildren(name, onEffect) {
  38. var _a;
  39. var path = "../" + name + "/index";
  40. return {
  41. relations: (_a = {},
  42. _a[path] = {
  43. type: 'descendant',
  44. linked: function (target) {
  45. onEffect && onEffect.call(this, target);
  46. },
  47. linkChanged: function (target) {
  48. onEffect && onEffect.call(this, target);
  49. },
  50. unlinked: function (target) {
  51. onEffect && onEffect.call(this, target);
  52. },
  53. },
  54. _a),
  55. mixin: Behavior({
  56. created: function () {
  57. var _this = this;
  58. Object.defineProperty(this, 'children', {
  59. get: function () { return _this.getRelationNodes(path) || []; },
  60. });
  61. },
  62. }),
  63. };
  64. }
  65. exports.useChildren = useChildren;