refactor: initalize meta classes in translator

This commit is contained in:
Rainer Killinger
2022-05-27 15:21:59 +02:00
parent 5277f7601c
commit 7b88be3a75

View File

@@ -77,6 +77,13 @@ export class SCThingTranslator {
this.sourceCache = new LRUCache(cacheCapacity); this.sourceCache = new LRUCache(cacheCapacity);
this._language = language; this._language = language;
this.metaClasses = SCClasses; this.metaClasses = SCClasses;
// Initalize all meta classes once
if (typeof (this.metaClasses as any)[Object.keys(this.metaClasses)[0]] === 'function') {
for (const metaClass of Object.keys(this.metaClasses)) {
(this.metaClasses as any)[metaClass] = new (SCClasses as any)[metaClass]();
}
}
} }
/** /**
@@ -143,7 +150,7 @@ export class SCThingTranslator {
*/ */
private getMetaClassInstance(thingType: SCThingType): any { private getMetaClassInstance(thingType: SCThingType): any {
if (thingType in this.metaClasses) { if (thingType in this.metaClasses) {
return new (this.metaClasses as any)[thingType](); return this.metaClasses[thingType];
} }
return undefined; return undefined;