diff --git a/main.ts b/main.ts index 84f0314..c77ca8b 100644 --- a/main.ts +++ b/main.ts @@ -17,19 +17,11 @@ const Observe = Record.makeConstructor>('Observe', ['label', 'observ function makeDataspace(): Entity { const handleMap: IdentityMap = new IdentityMap(); const assertions = new Bag>(); - const subscriptions: Dictionary>> = new Dictionary(); + const subscriptions: Dictionary, Dictionary>> = new Dictionary(); function forEachSubscription(assertion: Assertion, f: (handleMap: Dictionary, peer: Ref) => void): void { - if (Record.isRecord(assertion)) { - const peerMap = subscriptions.get(assertion.label); - if (Dictionary.isDictionary(peerMap)) { - peerMap.forEach((handleMap, peer) => { - if (peer instanceof Ref) { - f(handleMap, peer); - } - }); - } - } + if (!Record.isRecord(assertion)) return; + subscriptions.get(assertion.label)?.forEach(f); } return { @@ -42,7 +34,7 @@ function makeDataspace(): Entity { const observer = Observe._.observer(assertion) as Ref; let peerMap = subscriptions.get(observedLabel); if (peerMap === void 0) { - peerMap = new Dictionary(); + peerMap = new Map(); subscriptions.set(observedLabel, peerMap); } const handleMap: Dictionary = new Dictionary(); @@ -78,7 +70,7 @@ function makeDataspace(): Entity { }); if (Observe.isClassOf(assertion)) { let peerMap = subscriptions.get(Observe._.label(assertion)!)!; - peerMap.delete(Observe._.observer(assertion)!); + peerMap.delete(Observe._.observer(assertion)! as Ref); if (peerMap.size === 0) subscriptions.delete(Observe._.label(assertion)!); } }