Implement remove a key from a map op (slate set to undefined)

This commit is contained in:
Ulion 2021-02-07 12:55:23 +08:00
parent 4576605958
commit 3f32575418
2 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { Element } from 'slate'
import { toSlatePath, toJS } from '../utils'
import { getTarget } from '../path'
import { setDataOp } from './set'
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
try {
@ -87,6 +88,12 @@ const opRemove = (
try {
const { index, path, obj, type } = op
if (type === 'map' && path) {
// remove a key from map, mapping to slate set a key's value to undefined.
ops.push(setDataOp(op, doc)(map, tmpDoc))
return [map, ops]
}
if (
map.hasOwnProperty(obj) &&
typeof map[obj] !== 'string' &&

View File

@ -3,7 +3,7 @@ import { Element, Node } from 'slate'
import { toSlatePath, toJS } from '../utils'
const setDataOp = (
export const setDataOp = (
{ key = '', obj, path, value }: Automerge.Diff,
doc: any
) => (map: any, tmpDoc: Element) => {