Guest User

Untitled

a guest
Feb 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. import { isObject } from "util";
  2.  
  3.  
  4. interface hasInterface {
  5. prop: string,
  6. target: any
  7. }
  8.  
  9. interface EntityParamInterface {
  10. name: string,
  11. hasMany?: Array<hasInterface>,
  12. hasOne?: Array<hasInterface>,
  13. }
  14.  
  15. const targets = [];
  16.  
  17. export function Entity(params: EntityParamInterface) {
  18. return (entity: Object|any) => {
  19.  
  20. // entity.hasMeny && console.log("entity", entity.hasMeny())
  21.  
  22. // // params.hasMany
  23. // // && Array.isArray(params.hasMany)
  24. // // && params.hasMany.length
  25. // // && params.hasMany.forEach((param) => {
  26.  
  27.  
  28. // // console.log('param', entity.hasMany());
  29. // entity.hasMany
  30. // && typeof entity.hasMany === 'function'
  31. // && entity.hasMany().forEach((param) => {
  32. // // if (typeof param.target !== 'function') return;
  33.  
  34. // let memoryValue = null;
  35. // // const target = param.target();
  36. // const target = param.target;
  37. // console.log('target', target)
  38.  
  39. // Object.defineProperty(entity.prototype, param.prop, {
  40. // get: function () {
  41. // return memoryValue;
  42. // },
  43. // set: function (values) {
  44. // console.log('set', values)
  45. // if (target instanceof Object === false) {
  46. // return;
  47. // }
  48. // console.log('target instanceof Object', target instanceof Object)
  49.  
  50. // if (values === null) {
  51. // return;
  52. // }
  53.  
  54. // if (Array.isArray(values) === false) {
  55. // return;
  56. // }
  57.  
  58. // memoryValue = values.map((value) => {
  59. // if (value === null) {
  60. // return;
  61. // }
  62.  
  63. // // if (value instanceof target) {
  64. // // return value;
  65. // // }
  66.  
  67. // console.log('Object.create(target)', Object.create(target));
  68.  
  69. // const targetObject = Object.assign(Object.create(target), value);
  70.  
  71. // return targetObject;
  72. // });
  73. // },
  74. // enumerable: true,
  75. // configurable: true
  76. // });
  77. // });
  78.  
  79. // // params.hasOne
  80. // // && Array.isArray(params.hasOne)
  81. // // && params.hasOne.length
  82. // // && params.hasOne.forEach((param) => {
  83. // // });
  84.  
  85. // entity.hasOne
  86. // && typeof entity.hasOne === 'function'
  87. // && entity.hasOne().forEach((param) => {
  88. // let memoryValue = null;
  89. // const target = param.target;
  90.  
  91. // Object.defineProperty(entity.prototype, param.prop, {
  92. // get: function () {
  93. // return memoryValue;
  94. // },
  95. // set: function (value) {
  96. // if (target instanceof Object === false) {
  97. // return;
  98. // }
  99.  
  100. // if (value === null) {
  101. // return;
  102. // }
  103.  
  104. // // if (value instanceof target) {
  105. // // memoryValue = value;
  106. // // return;
  107. // // }
  108.  
  109. // memoryValue = Object.assign(
  110. // Object.create(target),
  111. // value
  112. // );
  113.  
  114. // },
  115. // enumerable: true,
  116. // configurable: true
  117. // });
  118. // });
  119.  
  120. }
  121. }
  122. // setInterval(()=>{
  123.  
  124. // console.log('targets', targets);
  125. // }, 1000)
Add Comment
Please, Sign In to add comment