From 78662a0d77fbea293ef4f9d857767f5d8f63f8e8 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 24 Feb 2021 22:19:37 +0100 Subject: [PATCH] Simplify --- actor.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/actor.ts b/actor.ts index 80faa28..5786122 100644 --- a/actor.ts +++ b/actor.ts @@ -131,9 +131,7 @@ export class Turn { assert(ref: Ref, assertion: Assertion): Handle { const h = nextHandle++; this.enqueue(ref.relay, t => { - const a = ref.attenuation === void 0 - ? assertion - : runRewrites(ref.attenuation, assertion); + const a = runRewrites(ref.attenuation, assertion); if (a !== null) { this.actor.outbound.set(h, ref); ref.target.assert?.(t, a, h); @@ -167,9 +165,7 @@ export class Turn { } message(ref: Ref, assertion: Assertion): void { - const a = ref.attenuation === void 0 - ? assertion - : runRewrites(ref.attenuation, assertion); + const a = runRewrites(ref.attenuation, 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); } -export function runRewrites(a: Attenuation, v: Assertion): Assertion | null { - for (const r of a) { - const w = rewrite(r, v); - if (w === null) return null; - v = w; +export function runRewrites(a: Attenuation | undefined, v: Assertion): Assertion | null { + if (a !== void 0) { + for (const r of a) { + const w = rewrite(r, v); + if (w === null) return null; + v = w; + } } return v; }