mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
Implement remove a key from a map op (slate set to undefined)
This commit is contained in:
parent
4576605958
commit
3f32575418
@ -3,6 +3,7 @@ import { Element } from 'slate'
|
|||||||
|
|
||||||
import { toSlatePath, toJS } from '../utils'
|
import { toSlatePath, toJS } from '../utils'
|
||||||
import { getTarget } from '../path'
|
import { getTarget } from '../path'
|
||||||
|
import { setDataOp } from './set'
|
||||||
|
|
||||||
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
||||||
try {
|
try {
|
||||||
@ -87,6 +88,12 @@ const opRemove = (
|
|||||||
try {
|
try {
|
||||||
const { index, path, obj, type } = op
|
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 (
|
if (
|
||||||
map.hasOwnProperty(obj) &&
|
map.hasOwnProperty(obj) &&
|
||||||
typeof map[obj] !== 'string' &&
|
typeof map[obj] !== 'string' &&
|
||||||
|
@ -3,7 +3,7 @@ import { Element, Node } from 'slate'
|
|||||||
|
|
||||||
import { toSlatePath, toJS } from '../utils'
|
import { toSlatePath, toJS } from '../utils'
|
||||||
|
|
||||||
const setDataOp = (
|
export const setDataOp = (
|
||||||
{ key = '', obj, path, value }: Automerge.Diff,
|
{ key = '', obj, path, value }: Automerge.Diff,
|
||||||
doc: any
|
doc: any
|
||||||
) => (map: any, tmpDoc: Element) => {
|
) => (map: any, tmpDoc: Element) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user