import { Opaque, dict } from '@glimmer/util'; import { PathReference } from './path'; import { RootReference as IRootReference } from '../types'; import { VOLATILE_TAG, PathReference as IPathReference, RevisionTag } from '@glimmer/reference'; export default class RootReference implements IRootReference, IPathReference { private object: T; private chains = dict>(); public tag: RevisionTag = VOLATILE_TAG; constructor(object: T) { this.object = object; } value(): T { return this.object; } update(object: T) { this.object = object; // this.notify(); } get(prop: string): IPathReference { let chains = this.chains; if (prop in chains) return chains[prop]; return (chains[prop] = new PathReference(this, prop)); } chainFor(prop: string): IPathReference { let chains = this.chains; if (prop in chains) return chains[prop]; return null; } path(string) { return string.split('.').reduce((ref, part) => ref.get(part), this); } referenceFromParts(parts: string[]): IPathReference { return parts.reduce((ref, part) => ref.get(part) as IPathReference, this as IPathReference); } label() { return '[reference Root]'; } }