AggregateDescriptor.ts
37 lines
| 964 B
| video/mp2t
|
TypeScriptLexer
|
|
r41 | import { Descriptor, isDescriptor } from "./interfaces"; | ||
|
|
r34 | import { ActivationContext } from "./ActivationContext"; | ||
|
|
r41 | import { isPrimitive } from "util"; | ||
|
|
r34 | |||
|
|
r39 | export class AggregateDescriptor implements Descriptor { | ||
| _value: object; | ||||
|
|
r34 | |||
|
|
r39 | constructor(value: object) { | ||
| this._value = value; | ||||
|
|
r34 | } | ||
|
|
r41 | activate(context: ActivationContext) { | ||
| return this._parse(this._value, context, "$value"); | ||||
|
|
r34 | } | ||
|
|
r41 | // TODO: make async | ||
| _parse(value, context: ActivationContext, path: string) { | ||||
| if (isPrimitive(value)) | ||||
| return value; | ||||
| if (isDescriptor(value)) | ||||
| return context.activate(value, path); | ||||
| if (value instanceof Array) | ||||
| return value.map((x, i) => this._parse(x, context, `${path}[${i}]`)); | ||||
| const t = {}; | ||||
| for (const p of Object.keys(value)) | ||||
| t[p] = this._parse(value[p], context, `${path}.${p}`); | ||||
| return t; | ||||
|
|
r34 | } | ||
|
|
r41 | |||
| toString() { | ||||
| return "@walk"; | ||||
|
|
r34 | } | ||
| } | ||||
