fix: opRemove on reconnect

This commit is contained in:
Eric Maciel 2020-10-31 11:34:02 -04:00
parent 528fd3ab08
commit 24a7f917fe
3 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1 @@
export const rootKey = '00000000-0000-0000-0000-000000000000'

View File

@ -8,6 +8,7 @@ import opCreate from './create'
import { toJS } from '../utils'
import { SyncDoc } from '../model'
import { rootKey } from './constants'
const byAction = {
create: opCreate,
@ -16,8 +17,6 @@ const byAction = {
insert: opInsert
}
const rootKey = '00000000-0000-0000-0000-000000000000'
const toSlateOp = (ops: Automerge.Diff[], doc: SyncDoc) => {
const iterate = (acc: [any, any[]], op: Automerge.Diff): any => {
const action = byAction[op.action]

View File

@ -3,6 +3,7 @@ import { Element } from 'slate'
import { toSlatePath, toJS } from '../utils'
import { getTarget } from '../path'
import { rootKey } from './constants'
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
const { index, path, obj } = op
@ -73,6 +74,8 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
const key = path[path.length - 1]
if (key === 'cursors') return [map, ops]
// if we don't have a valid key and this is the root obj no slate op is needed
if (key === undefined && obj === rootKey) return [map, ops]
const fn = key === 'text' ? removeTextOp : removeNodeOp