import {fromJSON as behaviorItemFromJSON} from './registry'; export class Traversal { constructor() { this.hash = undefined; this.steps = []; this.value = undefined; } fromJSON(json) { this.steps = json.steps.map((step) => { switch (step.type) { case 'key': return step; case 'invoke': return { type: 'invoke', args: step.args.map((arg) => behaviorItemFromJSON(arg)), }; } }); if (json.value) { this.value = behaviorItemFromJSON(json.value); } if (json.hash) { this.hash = json.hash; } return this; } get(context) { return this.traverse(context); } traverse(context) { if (context) { return context.traverse(this); } } toJSON() { return { type: 'traversal', steps: this.steps.map((step) => { switch (step.type) { case 'key': return step; case 'invoke': return { type: 'invoke', args: step.args.map((arg) => arg.toJSON()), }; } }), value: this.value ? this.value.toJSON() : undefined, }; } }