Less ceremony around proxied retractions

This commit is contained in:
Tony Garnock-Jones 2021-03-03 11:48:07 +01:00
parent 1f5389b9cd
commit 1cf0d9f89f
2 changed files with 11 additions and 15 deletions

View File

@ -209,15 +209,17 @@ export class Turn {
} }
} }
retract(h: Handle): void { retract(h: Handle | undefined): void {
const peer = this.actor.outbound.get(h); if (h !== void 0) {
if (peer === void 0) return; const peer = this.actor.outbound.get(h);
this._retract(peer, h); if (peer === void 0) return;
this._retract(peer, h);
}
} }
replace(ref: Ref, h: Handle | undefined, assertion: Assertion): Handle { replace(ref: Ref, h: Handle | undefined, assertion: Assertion): Handle {
const newHandle = this.assert(ref, assertion); const newHandle = this.assert(ref, assertion);
if (h !== void 0) this.retract(h); this.retract(h);
return newHandle; return newHandle;
} }
@ -411,11 +413,8 @@ export function forwarder(t: Turn, ref: Ref): { proxy: Ref, revoker: Ref } {
}, },
retract(turn: Turn, handle: Handle): void { retract(turn: Turn, handle: Handle): void {
if (underlying === null) return; if (underlying === null) return;
const h = handleMap.get(handle); turn.retract(handleMap.get(handle));
if (h !== void 0) { handleMap.delete(handle);
turn.retract(h);
handleMap.delete(handle);
}
}, },
message(turn: Turn, body: Assertion): void { message(turn: Turn, body: Assertion): void {
if (underlying === null) return; if (underlying === null) return;

View File

@ -61,11 +61,8 @@ export class Dataspace implements Partial<Entity> {
this.handleMap.delete(upstreamHandle); this.handleMap.delete(upstreamHandle);
if (this.assertions.change(rec, -1) !== ChangeDescription.PRESENT_TO_ABSENT) return; if (this.assertions.change(rec, -1) !== ChangeDescription.PRESENT_TO_ABSENT) return;
this.subscriptions.get(rec.label)?.forEach((seen, _peer) => { this.subscriptions.get(rec.label)?.forEach((seen, _peer) => {
const downstreamHandle = seen.get(rec); turn.retract(seen.get(rec));
if (downstreamHandle !== void 0) { seen.delete(rec);
turn.retract(downstreamHandle);
seen.delete(rec);
}
}); });
if (Observe.isClassOf(rec)) { if (Observe.isClassOf(rec)) {
let peerMap = this.subscriptions.get(Observe._.label(rec)!)!; let peerMap = this.subscriptions.get(Observe._.label(rec)!)!;