1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

fix *ByTypeAsArray node methods to always return arrays

This commit is contained in:
Ian Storm Taylor
2017-05-09 22:28:39 -07:00
parent cb03f02d68
commit 12bbb630e1

View File

@@ -280,9 +280,14 @@ const Node = {
getBlocksByTypeAsArray(type) {
return this.nodes.reduce((array, node) => {
if (node.kind != 'block') return array
if (node.isLeafBlock() && node.type == type) return array.push(node)
return array.concat(node.getBlocksByTypeAsArray(type))
if (node.kind != 'block') {
return array
} else if (node.isLeafBlock() && node.type == type) {
array.push(node)
return array
} else {
return array.concat(node.getBlocksByTypeAsArray(type))
}
}, [])
},
@@ -766,9 +771,14 @@ const Node = {
getInlinesByTypeAsArray(type) {
return this.nodes.reduce((inlines, node) => {
if (node.kind == 'text') return inlines
if (node.isLeafInline() && node.type == type) return inlines.push(node)
return inlines.concat(node.getInlinesByTypeAsArray(type))
if (node.kind == 'text') {
return inlines
} else if (node.isLeafInline() && node.type == type) {
inlines.push(node)
return inlines
} else {
return inlines.concat(node.getInlinesByTypeAsArray(type))
}
}, [])
},