Simplify
This commit is contained in:
parent
63270a97b4
commit
78662a0d77
20
actor.ts
20
actor.ts
|
@ -131,9 +131,7 @@ export class Turn {
|
||||||
assert(ref: Ref, assertion: Assertion): Handle {
|
assert(ref: Ref, assertion: Assertion): Handle {
|
||||||
const h = nextHandle++;
|
const h = nextHandle++;
|
||||||
this.enqueue(ref.relay, t => {
|
this.enqueue(ref.relay, t => {
|
||||||
const a = ref.attenuation === void 0
|
const a = runRewrites(ref.attenuation, assertion);
|
||||||
? assertion
|
|
||||||
: runRewrites(ref.attenuation, assertion);
|
|
||||||
if (a !== null) {
|
if (a !== null) {
|
||||||
this.actor.outbound.set(h, ref);
|
this.actor.outbound.set(h, ref);
|
||||||
ref.target.assert?.(t, a, h);
|
ref.target.assert?.(t, a, h);
|
||||||
|
@ -167,9 +165,7 @@ export class Turn {
|
||||||
}
|
}
|
||||||
|
|
||||||
message(ref: Ref, assertion: Assertion): void {
|
message(ref: Ref, assertion: Assertion): void {
|
||||||
const a = ref.attenuation === void 0
|
const a = runRewrites(ref.attenuation, assertion);
|
||||||
? assertion
|
|
||||||
: runRewrites(ref.attenuation, assertion);
|
|
||||||
if (a !== null) this.enqueue(ref.relay, t => ref.target.message?.(t, assertion));
|
if (a !== null) this.enqueue(ref.relay, t => ref.target.message?.(t, assertion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,11 +257,13 @@ export function rewrite(r: Rewrite, v: Assertion): Assertion | null {
|
||||||
return instantiate(r.template, bindings);
|
return instantiate(r.template, bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runRewrites(a: Attenuation, v: Assertion): Assertion | null {
|
export function runRewrites(a: Attenuation | undefined, v: Assertion): Assertion | null {
|
||||||
for (const r of a) {
|
if (a !== void 0) {
|
||||||
const w = rewrite(r, v);
|
for (const r of a) {
|
||||||
if (w === null) return null;
|
const w = rewrite(r, v);
|
||||||
v = w;
|
if (w === null) return null;
|
||||||
|
v = w;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue