document bug fix

This commit is contained in:
Drew Ansbacher
2021-08-24 12:57:55 -06:00
committed by Aiden McClelland
parent a72c1c5499
commit 60320e3083
2 changed files with 8 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
export interface Validator<T> { export interface Validator<T> {
(operation: Operation, index: number, document: T, existingPathFragment: string): void (operation: Operation, index: number, doc: T, existingPathFragment: string): void
} }
export interface BaseOperation { export interface BaseOperation {
@@ -24,18 +24,18 @@ export type Doc = { [key: string]: any }
export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any> export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any>
export function getValueByPointer (document: any, pointer: string): any { export function getValueByPointer (doc: any, pointer: string): any {
if (pointer === '/') return document if (pointer === '/') return doc
const pathArr = pointer.split('/') const pathArr = pointer.split('/')
pathArr.shift() pathArr.shift()
try { try {
return pathArr.reduce((acc, next) => acc[next], document) return pathArr.reduce((acc, next) => acc[next], doc)
} catch (e) { } catch (e) {
return undefined 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 let undo: Operation | null = null
const pathArr = op.path.split('/') const pathArr = op.path.split('/')
pathArr.shift() pathArr.shift()
@@ -75,7 +75,7 @@ export function applyOperation (document: Doc, op: Operation): Operation | null
} }
} }
} }
}, document) }, doc)
return undo return undo
} }

View File

@@ -93,7 +93,7 @@ export class Store<T extends { [key: string]: any }> {
while (stashEntry && stashEntry.revision.id > id) { while (stashEntry && stashEntry.revision.id > id) {
stashEntry.undo.forEach(u => { stashEntry.undo.forEach(u => {
applyOperation(document, u) applyOperation(this.cache.data, u)
}) })
stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1] stashEntry = this.stash.nextLowerPair(stashEntry.revision.id)?.[1]
} }
@@ -114,7 +114,7 @@ export class Store<T extends { [key: string]: any }> {
success = true success = true
} catch (e) { } catch (e) {
undo.forEach(u => { undo.forEach(u => {
applyOperation(document, u) applyOperation(this.cache.data, u)
}) })
undo = [] undo = []
} }