Track observers per-assertion, not per-observer-ref, to repair incremental updates of pattern (!)

This commit is contained in:
Tony Garnock-Jones 2024-04-17 13:22:05 +02:00
parent 6d904d276e
commit 782f24687f
1 changed files with 6 additions and 7 deletions

View File

@ -79,7 +79,7 @@ export class Dataspace implements Partial<Entity> {
readonly options: DataspaceOptions; readonly options: DataspaceOptions;
readonly index = new Index(); readonly index = new Index();
readonly handleMap = new IdentityMap<Handle, Assertion>(); readonly handleMap = new IdentityMap<Handle, Assertion>();
readonly observerMap = new IdentityMap<Ref, DataspaceObserver>(); readonly observerMap = new KeyedDictionary<Ref, Observe, DataspaceObserver>();
readonly data = this; readonly data = this;
constructor(options?: DataspaceOptions) { constructor(options?: DataspaceOptions) {
@ -92,10 +92,9 @@ export class Dataspace implements Partial<Entity> {
if (is_new) { if (is_new) {
const o = toObserve(strip(v)); const o = toObserve(strip(v));
if (o !== void 0) { if (o !== void 0) {
const target = o.observer; const io = new DataspaceObserver(o.observer);
const observer = new DataspaceObserver(target); this.observerMap.set(o, io);
this.observerMap.set(target, observer); this.index.addObserver(o.pattern, io, Turn.active);
this.index.addObserver(o.pattern, observer, Turn.active);
} }
if (this.options.dumpIndex ?? false) this.index.dump(); if (this.options.dumpIndex ?? false) this.index.dump();
} }
@ -111,10 +110,10 @@ export class Dataspace implements Partial<Entity> {
if (is_last) { if (is_last) {
const o = toObserve(strip(v)); const o = toObserve(strip(v));
if (o !== void 0) { if (o !== void 0) {
const io = this.observerMap.get(o.observer); const io = this.observerMap.get(o);
if (io !== void 0) { if (io !== void 0) {
this.index.removeObserver(o.pattern, io, Turn.active); this.index.removeObserver(o.pattern, io, Turn.active);
this.observerMap.delete(o.observer); this.observerMap.delete(o);
} }
} }
if (this.options.dumpIndex ?? false) this.index.dump(); if (this.options.dumpIndex ?? false) this.index.dump();