diff --git a/src/value/array.ts b/src/value/array.ts index cf97a2c..a5f1549 100644 --- a/src/value/array.ts +++ b/src/value/array.ts @@ -2,15 +2,9 @@ import {IToXmlOptioned} from '../options'; import {IElement, xmlElementChildElements} from '../util'; import {Value} from '../value'; -import {ValueBoolean} from './boolean'; -import {ValueData} from './data'; -import {ValueDate} from './date'; -import {ValueDict} from './dict'; -import {ValueInteger} from './integer'; -import {ValueReal} from './real'; -import {ValueString} from './string'; +import * as tags from './index'; -let childTagNames: Map Value>; +let childTagNames: Readonly Value>>; /** * ValueArray object. @@ -34,33 +28,17 @@ export class ValueArray extends Value { public static get CHILD_TAG_NAMES() { if (!childTagNames) { childTagNames = new Map(); - for (const Value of [ - ValueArray, - ValueBoolean, - ValueData, - ValueDate, - ValueDict, - ValueInteger, - ValueReal, - ValueString - ]) { - for (const t of Value.TAG_NAMES) { - childTagNames.set(t, Value); + for (const ValueType of Object.values(tags)) { + if (ValueType && ValueType.prototype instanceof Value) { + for (const t of ValueType.TAG_NAMES) { + childTagNames.set(t, ValueType); + } } } } return childTagNames; } - /** - * Child types. - * - * @returns Child tag names map. - */ - public get childTagNames() { - return (this.constructor as typeof ValueArray).CHILD_TAG_NAMES; - } - /** * Value value. */ @@ -193,7 +171,8 @@ export class ValueArray extends Value { */ public childFromXmlElement(element: Readonly) { const type = element.tagName; - const Value = this.childTagNames.get(type) || null; + const {CHILD_TAG_NAMES} = this.constructor as typeof ValueArray; + const Value = CHILD_TAG_NAMES.get(type) || null; if (!Value) { throw new Error(`Unknown element type: ${type}`); } diff --git a/src/value/dict.ts b/src/value/dict.ts index 03594b2..00348bb 100644 --- a/src/value/dict.ts +++ b/src/value/dict.ts @@ -2,15 +2,9 @@ import {IToXmlOptioned} from '../options'; import {IElement, xmlElementChildElements} from '../util'; import {Value} from '../value'; -import {ValueArray} from './array'; -import {ValueBoolean} from './boolean'; -import {ValueData} from './data'; -import {ValueDate} from './date'; -import {ValueInteger} from './integer'; -import {ValueReal} from './real'; -import {ValueString} from './string'; +import * as tags from './index'; -let childTagNames: Map Value>; +let childTagNames: Readonly Value>>; /** * ValueDict object. @@ -34,33 +28,17 @@ export class ValueDict extends Value { public static get CHILD_TAG_NAMES() { if (!childTagNames) { childTagNames = new Map(); - for (const Value of [ - ValueArray, - ValueBoolean, - ValueData, - ValueDate, - ValueDict, - ValueInteger, - ValueReal, - ValueString - ]) { - for (const t of Value.TAG_NAMES) { - childTagNames.set(t, Value); + for (const ValueType of Object.values(tags)) { + if (ValueType && ValueType.prototype instanceof Value) { + for (const t of ValueType.TAG_NAMES) { + childTagNames.set(t, ValueType); + } } } } return childTagNames; } - /** - * Child types. - * - * @returns Child tag names map. - */ - public get childTagNames() { - return (this.constructor as typeof ValueArray).CHILD_TAG_NAMES; - } - /** * Value value. */ @@ -178,7 +156,8 @@ export class ValueDict extends Value { */ public childFromXmlElement(element: Readonly) { const type = element.tagName; - const Value = this.childTagNames.get(type) || null; + const {CHILD_TAG_NAMES} = this.constructor as typeof ValueDict; + const Value = CHILD_TAG_NAMES.get(type) || null; if (!Value) { throw new Error(`Unknown element type: ${type}`); }