relation.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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:
  9. ((_a = {}),
  10. (_a[path] = {
  11. type: 'ancestor',
  12. linked: function () {
  13. onEffect && onEffect.call(this);
  14. },
  15. linkChanged: function () {
  16. onEffect && onEffect.call(this);
  17. },
  18. unlinked: function () {
  19. onEffect && onEffect.call(this);
  20. },
  21. }),
  22. _a),
  23. mixin: Behavior({
  24. created: function () {
  25. var _this = this;
  26. Object.defineProperty(this, 'parent', {
  27. get: function () {
  28. return _this.getRelationNodes(path)[0];
  29. },
  30. });
  31. Object.defineProperty(this, 'index', {
  32. // @ts-ignore
  33. get: function () {
  34. var _a, _b;
  35. return (_b =
  36. (_a = _this.parent) === null || _a === void 0
  37. ? void 0
  38. : _a.children) === null || _b === void 0
  39. ? void 0
  40. : _b.indexOf(_this);
  41. },
  42. });
  43. },
  44. }),
  45. };
  46. }
  47. exports.useParent = useParent;
  48. function useChildren(name, onEffect) {
  49. var _a;
  50. var path = '../' + name + '/index';
  51. return {
  52. relations:
  53. ((_a = {}),
  54. (_a[path] = {
  55. type: 'descendant',
  56. linked: function (target) {
  57. onEffect && onEffect.call(this, target);
  58. },
  59. linkChanged: function (target) {
  60. onEffect && onEffect.call(this, target);
  61. },
  62. unlinked: function (target) {
  63. onEffect && onEffect.call(this, target);
  64. },
  65. }),
  66. _a),
  67. mixin: Behavior({
  68. created: function () {
  69. var _this = this;
  70. Object.defineProperty(this, 'children', {
  71. get: function () {
  72. return _this.getRelationNodes(path) || [];
  73. },
  74. });
  75. },
  76. }),
  77. };
  78. }
  79. exports.useChildren = useChildren;