handle escaping and honor root pointer (#52)

* handle escaping and honor root pointer

* Update client/lib/json-patch-lib.ts

* Update client/lib/json-patch-lib.ts

Co-authored-by: Lucy C <12953208+elvece@users.noreply.github.com>
This commit is contained in:
Matt Hill
2022-10-03 10:56:50 -06:00
committed by GitHub
parent 00564ca1ca
commit 6c3079786f
2 changed files with 33 additions and 10 deletions

View File

@@ -10,8 +10,9 @@ import {
} from 'rxjs'
import {
applyOperation,
arrayFromPath,
getValueByPointer,
jsonPathToKeyArray,
pathFromArray,
} from './json-patch-lib'
export class PatchDB<T extends { [key: string]: any }> {
@@ -133,12 +134,12 @@ export class PatchDB<T extends { [key: string]: any }> {
filter(({ sequence }) => !!sequence),
take(1),
switchMap(({ data }) => {
const path = args.length ? `/${args.join('/')}` : ''
const path = pathFromArray(args)
if (!this.watchedNodes[path]) {
const value = getValueByPointer(data, path)
this.watchedNodes[path] = {
subject: new BehaviorSubject(value),
pathArr: jsonPathToKeyArray(path),
pathArr: arrayFromPath(path),
}
}
return this.watchedNodes[path].subject
@@ -183,7 +184,7 @@ export class PatchDB<T extends { [key: string]: any }> {
}
private updateWatchedNodes(revisionPath: string, data: T): void {
const r = jsonPathToKeyArray(revisionPath)
const r = arrayFromPath(revisionPath)
Object.entries(this.watchedNodes).forEach(([path, { pathArr }]) => {
if (startsWith(pathArr, r) || startsWith(r, pathArr)) {
this.updateWatchedNode(path, data)