From bb731c62ade154da4cdf09ca88b60bf7899d7284 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Wed, 14 Sep 2022 10:25:04 -0600 Subject: [PATCH] update children too --- client/lib/patch-db.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/lib/patch-db.ts b/client/lib/patch-db.ts index 8a318ee..f91966c 100644 --- a/client/lib/patch-db.ts +++ b/client/lib/patch-db.ts @@ -127,6 +127,7 @@ export class PatchDB { if (update.id < expected) return if (update.id > expected) { return console.error( + // unreachable `Received futuristic revision. Expected ${expected}, got ${update.id}`, ) } @@ -146,19 +147,20 @@ export class PatchDB { }) // update watched nodes revision.patch.forEach(op => { - Object.keys(this.watchedNodes).forEach(watchedPath => { - const revisionPath = op.path - if (revisionPath.includes(watchedPath)) { - this.updateWatchedNode(watchedPath, cache.data) - } - }) + this.updateWatchedNodes(op.path, cache.data) }) } private handleDump(dump: Dump, cache: DBCache): void { cache.data = { ...dump.value } + this.updateWatchedNodes('', cache.data) + } + + private updateWatchedNodes(revisionPath: string, data: T): void { Object.keys(this.watchedNodes).forEach(path => { - this.updateWatchedNode(path, cache.data) + if (path.includes(revisionPath) || revisionPath.includes(path)) { + this.updateWatchedNode(path, data) + } }) }