mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
only update nodes once per patch (#55)
This commit is contained in:
@@ -173,22 +173,19 @@ export class PatchDB<T extends { [key: string]: any }> {
|
|||||||
applyOperation(cache, op)
|
applyOperation(cache, op)
|
||||||
})
|
})
|
||||||
// update watched nodes
|
// update watched nodes
|
||||||
revision.patch.forEach(op => {
|
Object.entries(this.watchedNodes).forEach(([watchedPath, { pathArr }]) => {
|
||||||
this.updateWatchedNodes(op.path, cache.data)
|
const match = revision.patch.find(({ path }) => {
|
||||||
|
const arr = arrayFromPath(path)
|
||||||
|
return startsWith(pathArr, arr) || startsWith(arr, pathArr)
|
||||||
|
})
|
||||||
|
if (match) this.updateWatchedNode(watchedPath, cache.data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleDump(dump: Dump<T>, cache: DBCache<T>): void {
|
private handleDump(dump: Dump<T>, cache: DBCache<T>): void {
|
||||||
cache.data = { ...dump.value }
|
cache.data = { ...dump.value }
|
||||||
this.updateWatchedNodes('', cache.data)
|
Object.keys(this.watchedNodes).forEach(watchedPath => {
|
||||||
}
|
this.updateWatchedNode(watchedPath, cache.data)
|
||||||
|
|
||||||
private updateWatchedNodes(revisionPath: string, data: T): void {
|
|
||||||
const r = arrayFromPath(revisionPath)
|
|
||||||
Object.entries(this.watchedNodes).forEach(([path, { pathArr }]) => {
|
|
||||||
if (startsWith(pathArr, r) || startsWith(r, pathArr)) {
|
|
||||||
this.updateWatchedNode(path, data)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user