fix: opSet conversion for rootKey

This commit is contained in:
Eric Maciel 2020-10-31 11:41:31 -04:00
parent 09985bc1f3
commit c21172517a

View File

@ -1,6 +1,7 @@
import * as Automerge from 'automerge' import * as Automerge from 'automerge'
import { toSlatePath, toJS } from '../utils' import { toSlatePath, toJS } from '../utils'
import { rootKey } from './constants'
const setDataOp = ( const setDataOp = (
{ key = '', obj, path, value }: Automerge.Diff, { key = '', obj, path, value }: Automerge.Diff,
@ -22,6 +23,11 @@ const opSet = (op: Automerge.Diff, [map, ops]: any, doc: any) => {
const { link, value, path, obj, key } = op const { link, value, path, obj, key } = op
try { try {
// no slate op needed for root key cursor updates
if (obj === rootKey && key === 'cursors') {
return [map, ops]
}
if (path && path[0] !== 'cursors') { if (path && path[0] !== 'cursors') {
ops.push(setDataOp(op, doc)) ops.push(setDataOp(op, doc))
} else if (map[obj]) { } else if (map[obj]) {