1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 17:39:57 +02:00

fix to always default operation.data to an object

This commit is contained in:
Ian Storm Taylor
2018-11-11 14:34:05 -08:00
parent 585dc85185
commit eb7ad70dde
2 changed files with 7 additions and 5 deletions

View File

@@ -126,6 +126,11 @@ class Operation extends Record(DEFAULTS) {
for (const key of ATTRIBUTES) {
let v = object[key]
// Default `data` to an empty object.
if (key === 'data' && v === undefined) {
v = {}
}
if (v === undefined) {
// Skip keys for objects that should not be serialized, and are only used
// for providing the local-only invert behavior for the history stack.
@@ -134,9 +139,6 @@ class Operation extends Record(DEFAULTS) {
if (key == 'value') continue
if (key == 'node' && type != 'insert_node') continue
// Skip optional user defined data
if (key == 'data') continue
throw new Error(
`\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.`
)
@@ -311,7 +313,7 @@ class Operation extends Record(DEFAULTS) {
value = v
}
if (key === 'data' && value) {
if (key === 'data') {
value = value.toJSON()
}

View File

@@ -23,5 +23,5 @@ export const output = {
object: 'mark',
type: 'b',
},
data: undefined,
data: {},
}