From 60320e3083e6157db8efbcd029a8b58ae6aafd97 Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Tue, 24 Aug 2021 12:57:55 -0600 Subject: [PATCH] document bug fix --- client/lib/json-patch-lib.ts | 12 ++++++------ client/lib/store.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/lib/json-patch-lib.ts b/client/lib/json-patch-lib.ts index c88371b..bd60cf1 100644 --- a/client/lib/json-patch-lib.ts +++ b/client/lib/json-patch-lib.ts @@ -1,5 +1,5 @@ export interface Validator { - (operation: Operation, index: number, document: T, existingPathFragment: string): void + (operation: Operation, index: number, doc: T, existingPathFragment: string): void } export interface BaseOperation { @@ -24,18 +24,18 @@ export type Doc = { [key: string]: any } export type Operation = AddOperation | RemoveOperation | ReplaceOperation -export function getValueByPointer (document: any, pointer: string): any { - if (pointer === '/') return document +export function getValueByPointer (doc: any, pointer: string): any { + if (pointer === '/') return doc const pathArr = pointer.split('/') pathArr.shift() try { - return pathArr.reduce((acc, next) => acc[next], document) + return pathArr.reduce((acc, next) => acc[next], doc) } catch (e) { return undefined } } -export function applyOperation (document: Doc, op: Operation): Operation | null { +export function applyOperation (doc: Doc, op: Operation): Operation | null { let undo: Operation | null = null const pathArr = op.path.split('/') pathArr.shift() @@ -75,7 +75,7 @@ export function applyOperation (document: Doc, op: Operation): Operation | null } } } - }, document) + }, doc) return undo } diff --git a/client/lib/store.ts b/client/lib/store.ts index 3b9ea68..4ae4625 100644 --- a/client/lib/store.ts +++ b/client/lib/store.ts @@ -93,7 +93,7 @@ export class Store { while (stashEntry && stashEntry.revision.id > id) { stashEntry.undo.forEach(u => { - applyOperation(document, u) + applyOperation(this.cache.data, u) }) stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1] } @@ -114,7 +114,7 @@ export class Store { success = true } catch (e) { undo.forEach(u => { - applyOperation(document, u) + applyOperation(this.cache.data, u) }) undo = [] }