2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 04:22:58 +00:00
This commit is contained in:
Ahmed Zamil 2022-09-18 23:58:24 +03:00
parent 735a19cda3
commit b198101e2d
5 changed files with 34 additions and 44 deletions

View File

@ -76,6 +76,12 @@ export default class AutoList extends IEventHandler
return this.list[index]; return this.list[index];
} }
first(selector){
for(var el of this.list)
if (selector(el))
return el;
}
remove(value) remove(value)
{ {
this.removeAt(this.list.indexOf(value)); this.removeAt(this.list.indexOf(value));

View File

@ -1918,12 +1918,12 @@ export default class DistributedConnection extends IStore {
let parsed = Codec.parse(content, 0, this, null, transmissionType); let parsed = Codec.parse(content, 0, this, null, transmissionType);
parsed.Then(results => parsed.then(results =>
{ {
// un hold the socket to send data immediately // un hold the socket to send data immediately
this.socket.unhold(); this.socket.unhold();
var fi = ft.MethodInfo; var fi = ft.methodInfo;
if (fi == null) if (fi == null)
{ {

View File

@ -3,8 +3,11 @@ import Warehouse from "../Resource/Warehouse.js";
export default class ResourceProxy { export default class ResourceProxy {
static cache = {}; static cache = {};
static getBase(type) { static getBaseType(type) {
if (type.baseType != null) if (type == null)
throw new Error("Type can't be null.");
if (type.baseType != null)
return type.baseType; return type.baseType;
return type; return type;

View File

@ -137,7 +137,7 @@ export default class TypeTemplate {
var list = []; var list = [];
list.add(template); list.push(template);
var getDependenciesFunc = null; var getDependenciesFunc = null;
@ -161,11 +161,11 @@ export default class TypeTemplate {
} }
} }
var args = ft.methodInfo.parameters; var args = ft.methodInfo.args;
for(let j = 0; j < args.length - 1; j++) for(let j = 0; j < args.length - 1; j++)
{ {
var fpt = Warehouse.getTemplateByType(args[j].parameterType); var fpt = Warehouse.getTemplateByType(args[j].type);
if (fpt != null) if (fpt != null)
{ {
if (!bag.includes(fpt)) if (!bag.includes(fpt))
@ -180,9 +180,9 @@ export default class TypeTemplate {
if (args.length > 0) if (args.length > 0)
{ {
var last = args[args.length - 1]; var last = args[args.length - 1];
if (last.parameterType == DistributedConnection) if (last.type == DistributedConnection)
{ {
let fpt = Warehouse.getTemplateByType(last.parameterType); let fpt = Warehouse.getTemplateByType(last.type);
if (fpt != null) if (fpt != null)
{ {
if (!bag.includes(fpt)) if (!bag.includes(fpt))
@ -200,7 +200,7 @@ export default class TypeTemplate {
for (let i = 0; i < tmp.properties.length; i++) for (let i = 0; i < tmp.properties.length; i++)
{ {
var p = tmp.properties[i]; var p = tmp.properties[i];
var pt = Warehouse.getTemplateByType(p.propertyInfo.propertyType); var pt = Warehouse.getTemplateByType(p.propertyInfo.type);
if (pt != null) if (pt != null)
{ {
if (!bag.includes(pt)) if (!bag.includes(pt))
@ -215,13 +215,13 @@ export default class TypeTemplate {
for(let i = 0; i < tmp.events.length; i++) for(let i = 0; i < tmp.events.length; i++)
{ {
var e = tmp.events[i]; var e = tmp.events[i];
var et = Warehouse.getTemplateByType(e.eventInfo.eventHandlerType); var et = Warehouse.getTemplateByType(e.eventInfo.type);
if (et != null) if (et != null)
{ {
if (!bag.includes(et)) if (!bag.includes(et))
{ {
bag.Add(et); bag.add(et);
getDependenciesFunc(et, bag); getDependenciesFunc(et, bag);
} }
} }

View File

@ -312,51 +312,32 @@ export class WH extends IEventHandler
getTemplateByType(type) getTemplateByType(type)
{ {
if (type == null)
let baseType = ResourceProxy.getBaseType(type);
if (baseType == IResource || baseType == IRecord || baseType == IEnum)
return null; return null;
// search our records // search our records
let template = this.templates.first(x=> x.defineType == type);
if (template != null)
return template;
let templateType; let templateType;
if (type.prototype instanceof IResource) if (baseType.prototype instanceof IResource)
templateType = TemplateType.Resource; templateType = TemplateType.Resource;
else if (type.prototype instanceof IRecord) else if (baseType.prototype instanceof IRecord)
templateType = TemplateType.Record; templateType = TemplateType.Record;
else if (type.prototype instanceof IEnum) else if (baseType.prototype instanceof IEnum)
templateType = TemplateType.Enum; templateType = TemplateType.Enum;
else else
return null; return null;
if (type == IResource let template = this.templates.item(templateType).first(x=> x.definedType == baseType);
|| type == IRecord) if (template != null)
return null; return template;
template = new TypeTemplate(baseType, true);
TypeTemplate.getDependencies(template);
if (!(type.prototype instanceof IResource
|| type.prototype instanceof IRecord))
return false;
// let className = type.prototype.constructor.name;
// if (className.startsWith("E_"))
// className = className.substr(2);
// className = type.template.namespace + "." + (type.template.className ?? className);
// var templates = this.templates.get(templateType);
// // loaded ?
// for(var i = 0; i < templates.length; i++)
// if (templates.at(i).className == className)
// return templates.at(i);
template = new TypeTemplate(type, true);
return template; return template;
} }