Better Ref printing

This commit is contained in:
Tony Garnock-Jones 2021-12-09 18:51:41 +01:00
parent ffee492fec
commit b5e82cba9b
1 changed files with 26 additions and 1 deletions

View File

@ -34,6 +34,31 @@ export interface Ref {
readonly attenuation?: Attenuation;
}
export class RefImpl implements Ref {
readonly relay: Facet;
readonly target: Partial<Entity>;
readonly attenuation?: Attenuation;
constructor(relay: Facet, target: Partial<Entity>, attenuation?: Attenuation) {
this.relay = relay;
this.target = target;
this.attenuation = attenuation;
}
toString() {
let entityRepr = '' + this.target;
if (entityRepr === '[object Object]') {
entityRepr = '#' + embeddedId(this.target);
}
let sig = '';
if ('assert' in this.target) sig = sig + 'A';
if ('retract' in this.target) sig = sig + 'R';
if ('message' in this.target) sig = sig + 'M';
if ('sync' in this.target) sig = sig + 'S';
return `${this.relay.idChain()}<${sig}>${entityRepr}`;
}
}
//---------------------------------------------------------------------------
export function isRef(v: any): v is Ref {
@ -262,7 +287,7 @@ export class Turn {
}
ref<T extends Partial<Entity>>(e: T): Ref {
return { relay: this.activeFacet, target: e };
return new RefImpl(this.activeFacet, e);
}
facet(bootProc: LocalAction): Facet {