mirror of
				https://github.com/esiur/esiur-js.git
				synced 2025-10-29 17:10:30 +00:00 
			
		
		
		
	TemplateType.Wrapper Removed
This commit is contained in:
		| @@ -138,7 +138,7 @@ export default class RepresentationType { | ||||
|     if (IdentifierToTypeMap[this.identifier] != undefined) | ||||
|       runtimeType = IdentifierToTypeMap[this.identifier] | ||||
|     if (this.identifier == RepresentationTypeIdentifier.TypedResource) { | ||||
|       runtimeType = Warehouse.getTemplateByClassId(this.guid)?.definedType; | ||||
|       runtimeType = Warehouse.getTemplateByClassId(this.guid, TemplateType.Resource)?.definedType; | ||||
|     } else if (this.identifier == RepresentationTypeIdentifier.TypedRecord) { | ||||
|       runtimeType = Warehouse.getTemplateByClassId(this.guid, TemplateType.Record)?.definedType; | ||||
|     } else if (this.identifier == RepresentationTypeIdentifier.Enum) { | ||||
|   | ||||
| @@ -2584,8 +2584,8 @@ export default class DistributedConnection extends IStore { | ||||
|  | ||||
|                 if (resource == null) | ||||
|                 { | ||||
|                     template = Warehouse.getTemplateByClassId(classId, TemplateType.Wrapper); | ||||
|                     if (template?.definedType != null) | ||||
|                     template = Warehouse.getTemplateByClassId(classId, TemplateType.Resource); | ||||
|                     if (template?.definedType != null && template?.isWrapper) | ||||
|                         dr = new template.definedType(self, id, rt[1], rt[2]); | ||||
|                     else | ||||
|                         dr = new DistributedResource(self, id, rt[1], rt[2]); | ||||
|   | ||||
| @@ -119,8 +119,7 @@ export default class TemplateGenerator { | ||||
|             let className = templates | ||||
|             .find((x) => | ||||
|                 x.classId.valueOf() == representationType.guid.valueOf() && | ||||
|                 (x.type == TemplateType.Resource || | ||||
|                     x.type == TemplateType.Wrapper)) | ||||
|                 (x.type == TemplateType.Resource)) | ||||
|             .className; | ||||
|             if (!dependencies?.includes(className)) dependencies?.push(className); | ||||
|             name = this._translateClassName(className); | ||||
| @@ -386,8 +385,7 @@ export default class TemplateGenerator { | ||||
|       let parentClassName = templates | ||||
|           .find((x) => | ||||
|               (x.classId.valueOf() == template.parentId.valueOf()) && | ||||
|               (x.type == TemplateType.Resource || | ||||
|                   x.type == TemplateType.Wrapper)) | ||||
|               (x.type == TemplateType.Resource)) | ||||
|           .className; | ||||
|       parentName = this._translateClassName(parentClassName); | ||||
|       dependencies.push(parentClassName); | ||||
|   | ||||
| @@ -39,6 +39,7 @@ import TypedList from '../Data/TypedList.js'; | ||||
| import EventOccurredInfo from './EventOccurredInfo.js'; | ||||
| import PropertyModificationInfo from './PropertyModificationInfo.js'; | ||||
| import PropertyValueArray from '../Data/PropertyValueArray.js'; | ||||
| import DistributedResource from '../Net/IIP/DistributedResource.js'; | ||||
|  | ||||
| export default class Instance extends IEventHandler | ||||
| { | ||||
| @@ -265,9 +266,10 @@ export default class Instance extends IEventHandler | ||||
|         } | ||||
|  | ||||
|         // connect events | ||||
|         for (let i = 0; i < this.template.events.length; i++) | ||||
|            resource.on(this.template.events[i].name, this._makeHandler(this.template.events[i])); | ||||
|          | ||||
|         if (!(resource instanceof DistributedResource)) { | ||||
|             for (let i = 0; i < this.template.events.length; i++) | ||||
|                 resource.on(this.template.events[i].name, this._makeHandler(this.template.events[i])); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     _makeHandler(eventTemplate) | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
| export default  | ||||
| { | ||||
|     Unspecified: 0, | ||||
|     Resource: 1, | ||||
|     Record: 2, | ||||
|     Wrapper: 3, | ||||
|     Enum: 4 | ||||
|     Resource: 0, | ||||
|     Record: 1, | ||||
|     Enum: 2 | ||||
| } | ||||
| @@ -42,6 +42,13 @@ import Codec from '../../Data/Codec.js'; | ||||
|  | ||||
| export default class TypeTemplate { | ||||
|  | ||||
|     isWrapper = false; | ||||
|     properties = []; | ||||
|     events = []; | ||||
|     functions = []; | ||||
|     members = []; | ||||
|     constants = []; | ||||
|  | ||||
|     getEventTemplateByName(eventName) { | ||||
|         for (var i = 0; i < this.events.length; i++) | ||||
|             if (this.events[i].name == eventName) | ||||
| @@ -222,7 +229,8 @@ export default class TypeTemplate { | ||||
|          }; | ||||
|  | ||||
|          getDependenciesFunc(template, list); | ||||
|          return list; | ||||
|  | ||||
|          return list.filter((value, index, self) => self.indexOf(value) === index); | ||||
|      } | ||||
|  | ||||
|      get type() { | ||||
| @@ -231,20 +239,12 @@ export default class TypeTemplate { | ||||
|  | ||||
|     constructor(type, addToWarehouse) { | ||||
|  | ||||
|  | ||||
|         this.properties = []; | ||||
|         this.events = []; | ||||
|         this.functions = []; | ||||
|         this.members = []; | ||||
|         this.constants = []; | ||||
|  | ||||
|          | ||||
|       | ||||
|         if (type === undefined) | ||||
|             return; | ||||
|          | ||||
|         if (type.prototype instanceof DistributedResource) | ||||
|             this.templateType = TemplateType.Wrapper; | ||||
|         else if (type.prototype instanceof IRecord) | ||||
|              | ||||
|         if (type.prototype instanceof IRecord) | ||||
|             this.templateType = TemplateType.Record; | ||||
|         else if (type.prototype instanceof IResource) | ||||
|             this.templateType = TemplateType.Resource; | ||||
| @@ -253,6 +253,8 @@ export default class TypeTemplate { | ||||
|         else | ||||
|             throw new Error("Type must implement IResource, IRecord, IEnum or a subtype of DistributedResource."); | ||||
|  | ||||
|         this.isWrapper = (type.prototype instanceof DistributedResource); | ||||
|  | ||||
|         this.definedType = type; | ||||
|  | ||||
|         let describer = type.template; | ||||
|   | ||||
| @@ -55,18 +55,16 @@ export class WH extends IEventHandler | ||||
|         this.resourceCounter = 0; | ||||
|         this.templates = new KeyList(); | ||||
|  | ||||
|         this.templates.add(TemplateType.Unspecified, new KeyList()); | ||||
|         this.templates.add(TemplateType.Resource, new KeyList()); | ||||
|         this.templates.add(TemplateType.Record, new KeyList()); | ||||
|         this.templates.add(TemplateType.Wrapper, new KeyList()); | ||||
|         this.templates.add(TemplateType.Enum, new KeyList()); | ||||
|  | ||||
|         this.protocols = new KeyList(); | ||||
|  | ||||
|         this._register("connected"); | ||||
|         this._register("disconnected"); | ||||
|         ///this._urlRegex = /^(?:([\S]*):\/\/([^\/]*)\/?)/; | ||||
| //        this._urlRegex = /^(?:([^\s|:]*):\/\/([^\/]*)\/?)/; | ||||
|  | ||||
|          | ||||
|         this._urlRegex = /^(?:([^\s|:]*):\/\/([^/]*)\/?)/; | ||||
|  | ||||
|     } | ||||
| @@ -306,6 +304,9 @@ export class WH extends IEventHandler | ||||
|  | ||||
|     putTemplate(template) | ||||
|     { | ||||
|         if (this.templates.get(template.type).containsKey(template.classId)) | ||||
|             throw new Error("Template with same class Id already exists."); | ||||
|    | ||||
|         this.templates.get(template.type).add(template.classId, template); | ||||
|     } | ||||
|  | ||||
| @@ -314,11 +315,9 @@ export class WH extends IEventHandler | ||||
|         if (type == null) | ||||
|             return null; | ||||
|  | ||||
|         var templateType = TemplateType.Unspecified; | ||||
|         let templateType; | ||||
|  | ||||
|         if (type.prototype instanceof DistributedResource) | ||||
|             templateType = TemplateType.Wrapper; | ||||
|         else if (type.prototype instanceof IResource) | ||||
|         if (type.prototype instanceof IResource) | ||||
|             templateType = TemplateType.Resource; | ||||
|         else if (type.prototype instanceof IRecord) | ||||
|             templateType = TemplateType.Record; | ||||
| @@ -355,44 +354,44 @@ export class WH extends IEventHandler | ||||
|         return template; | ||||
|     } | ||||
|  | ||||
|     getTemplateByClassId(classId, templateType = TemplateType.Unspecified) | ||||
|     getTemplateByClassId(classId, templateType = null) | ||||
|     { | ||||
|         if (templateType == TemplateType.Unspecified) | ||||
|         if (templateType == null) | ||||
|         { | ||||
|             // look in resources | ||||
|             // look into resources | ||||
|             var template = this.templates.get(TemplateType.Resource).get(classId); | ||||
|             if (template != null) | ||||
|                 return template; | ||||
|              | ||||
|             // look in records | ||||
|             // look into records | ||||
|             template = this.templates.get(TemplateType.Record).get(classId); | ||||
|             if (template != null) | ||||
|                 return template; | ||||
|  | ||||
|             // look in wrappers | ||||
|             template = this.templates.get(TemplateType.Wrapper).get(classId); | ||||
|             // look into enums | ||||
|             template = this.templates.get(TemplateType.Enum).get(classId); | ||||
|             return template; | ||||
|         } | ||||
|         else | ||||
|             return this.templates.get(templateType).get(classId); | ||||
|     } | ||||
|  | ||||
|     getTemplateByClassName(className, templateType = TemplateType.Unspecified) | ||||
|     getTemplateByClassName(className, templateType = null) | ||||
|     { | ||||
|         if (templateType == TemplateType.Unspecified) | ||||
|         if (templateType == null) | ||||
|         { | ||||
|             // look in resources | ||||
|             // look into resources | ||||
|             var template = this.templates.get(TemplateType.Resource).values.find(x => x.className == className); | ||||
|             if (template != null) | ||||
|                 return template; | ||||
|  | ||||
|             // look in records | ||||
|             // look into records | ||||
|             template = this.templates.get(TemplateType.Record).values.find(x => x.className == className); | ||||
|             if (template != null) | ||||
|                 return template; | ||||
|  | ||||
|             // look in wrappers | ||||
|             template = this.templates.get(TemplateType.Wrapper).values.find(x => x.className == className); | ||||
|             // look into enums | ||||
|             template = this.templates.get(TemplateType.Enum).values.find(x => x.className == className); | ||||
|             return template; | ||||
|         } | ||||
|         else | ||||
|   | ||||
		Reference in New Issue
	
	Block a user