mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +02:00
Optimize Node.getTexts to work on arrays
This commit is contained in:
@@ -978,11 +978,26 @@ const Node = {
|
||||
*/
|
||||
|
||||
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 node.kind == 'text'
|
||||
? texts.push(node)
|
||||
: texts.concat(node.getTexts())
|
||||
}, List())
|
||||
if (node.kind == 'text') {
|
||||
texts.push(node)
|
||||
return texts
|
||||
} else {
|
||||
return texts.concat(node._getTexts())
|
||||
}
|
||||
}, [])
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1390,7 +1405,7 @@ memoize(Node, [
|
||||
'getPreviousText',
|
||||
'getTextAtOffset',
|
||||
'getTextDirection',
|
||||
'getTexts',
|
||||
'_getTexts',
|
||||
'getTextsAtRange',
|
||||
'hasVoidParent',
|
||||
'isInlineSplitAtRange'
|
||||
|
Reference in New Issue
Block a user