mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 00:06:30 +02:00
Optimize Node.getTexts to work on arrays
This commit is contained in:
@@ -978,11 +978,26 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getTexts() {
|
getTexts() {
|
||||||
|
return List(this._getTexts())
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively get all of the child text nodes in order of appearance.
|
||||||
|
*
|
||||||
|
* @return {Array} nodes
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This one is memoized
|
||||||
|
|
||||||
|
_getTexts() {
|
||||||
return this.nodes.reduce((texts, node) => {
|
return this.nodes.reduce((texts, node) => {
|
||||||
return node.kind == 'text'
|
if (node.kind == 'text') {
|
||||||
? texts.push(node)
|
texts.push(node)
|
||||||
: texts.concat(node.getTexts())
|
return texts
|
||||||
}, List())
|
} else {
|
||||||
|
return texts.concat(node._getTexts())
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1390,7 +1405,7 @@ memoize(Node, [
|
|||||||
'getPreviousText',
|
'getPreviousText',
|
||||||
'getTextAtOffset',
|
'getTextAtOffset',
|
||||||
'getTextDirection',
|
'getTextDirection',
|
||||||
'getTexts',
|
'_getTexts',
|
||||||
'getTextsAtRange',
|
'getTextsAtRange',
|
||||||
'hasVoidParent',
|
'hasVoidParent',
|
||||||
'isInlineSplitAtRange'
|
'isInlineSplitAtRange'
|
||||||
|
Reference in New Issue
Block a user