2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-09-13 23:23:18 +00:00
This commit is contained in:
2021-02-20 00:09:06 +03:00
parent e6a28da68d
commit 0efb266c2a
14 changed files with 1458 additions and 905 deletions

View File

@@ -0,0 +1,41 @@
import Warehouse from "../Resource/Warehouse.js";
export default class ResourceProxy
{
static cache = {};
static getProxy(type)
{
var template = Warehouse.getTemplateByType(type);
var className = type.prototype.constructor.name;
if (ResourceProxy.cache[className])
return ResourceProxy.cache[className];
var code = `return (class E_${className} extends b { constructor() {super();} `;
// generate class
for(var i = 0; i < template.properties.length; i++)
{
let pt = template.properties[i];
let desc = Object.getOwnPropertyDescriptor(Payment.prototype, pt.name);
if (desc)
{
code += `\r\n set ${pt.name}(v) { \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); \r\n super.${pt.name} = v; } \r\n get ${pt.name}() { \r\n return super.${pt.name};}`;
}
else
{
code += `\r\n set ${pt.name}(v) { \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); \r\n super._${pt.name} = v; } \r\n get ${pt.name}() { \r\n return super._${pt.name};}`;
}
}
var func = new Function("b", code + "})");
var proxyType = func.call(type /* this */, type);
ResourceProxy.cache[className] = proxyType;
return proxyType;
}
}