Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { isObject } from "util";
- interface hasInterface {
- prop: string,
- target: any
- }
- interface EntityParamInterface {
- name: string,
- hasMany?: Array<hasInterface>,
- hasOne?: Array<hasInterface>,
- }
- const targets = [];
- export function Entity(params: EntityParamInterface) {
- return (entity: Object|any) => {
- // entity.hasMeny && console.log("entity", entity.hasMeny())
- // // params.hasMany
- // // && Array.isArray(params.hasMany)
- // // && params.hasMany.length
- // // && params.hasMany.forEach((param) => {
- // // console.log('param', entity.hasMany());
- // entity.hasMany
- // && typeof entity.hasMany === 'function'
- // && entity.hasMany().forEach((param) => {
- // // if (typeof param.target !== 'function') return;
- // let memoryValue = null;
- // // const target = param.target();
- // const target = param.target;
- // console.log('target', target)
- // Object.defineProperty(entity.prototype, param.prop, {
- // get: function () {
- // return memoryValue;
- // },
- // set: function (values) {
- // console.log('set', values)
- // if (target instanceof Object === false) {
- // return;
- // }
- // console.log('target instanceof Object', target instanceof Object)
- // if (values === null) {
- // return;
- // }
- // if (Array.isArray(values) === false) {
- // return;
- // }
- // memoryValue = values.map((value) => {
- // if (value === null) {
- // return;
- // }
- // // if (value instanceof target) {
- // // return value;
- // // }
- // console.log('Object.create(target)', Object.create(target));
- // const targetObject = Object.assign(Object.create(target), value);
- // return targetObject;
- // });
- // },
- // enumerable: true,
- // configurable: true
- // });
- // });
- // // params.hasOne
- // // && Array.isArray(params.hasOne)
- // // && params.hasOne.length
- // // && params.hasOne.forEach((param) => {
- // // });
- // entity.hasOne
- // && typeof entity.hasOne === 'function'
- // && entity.hasOne().forEach((param) => {
- // let memoryValue = null;
- // const target = param.target;
- // Object.defineProperty(entity.prototype, param.prop, {
- // get: function () {
- // return memoryValue;
- // },
- // set: function (value) {
- // if (target instanceof Object === false) {
- // return;
- // }
- // if (value === null) {
- // return;
- // }
- // // if (value instanceof target) {
- // // memoryValue = value;
- // // return;
- // // }
- // memoryValue = Object.assign(
- // Object.create(target),
- // value
- // );
- // },
- // enumerable: true,
- // configurable: true
- // });
- // });
- }
- }
- // setInterval(()=>{
- // console.log('targets', targets);
- // }, 1000)
Add Comment
Please, Sign In to add comment