mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
Greatly improve performance of normalizeChildrenWith
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import warning from '../utils/warning'
|
import warning from '../utils/warning'
|
||||||
import { default as defaultSchema } from '../plugins/schema'
|
import { default as defaultSchema } from '../plugins/schema'
|
||||||
import Normalize from '../utils/normalize'
|
import Normalize from '../utils/normalize'
|
||||||
|
import { Map } from 'immutable'
|
||||||
|
|
||||||
// Maximum recursive calls for normalization
|
// Maximum recursive calls for normalization
|
||||||
const MAX_CALLS = 50
|
const MAX_CALLS = 50
|
||||||
@@ -40,9 +41,13 @@ function _normalizeChildrenWith(transform, schema, node, prevNode) {
|
|||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prevChildrenMap = new Map().withMutations(map => {
|
||||||
|
if (prevNode) prevNode.nodes.forEach(n => map.set(n.key, n))
|
||||||
|
})
|
||||||
|
|
||||||
return node.nodes.reduce(
|
return node.nodes.reduce(
|
||||||
(t, child) => {
|
(t, child) => {
|
||||||
const prevChild = prevNode ? prevNode.getChild(child.key) : null
|
const prevChild = prevChildrenMap.get(child.key)
|
||||||
return t.normalizeNodeWith(schema, child, prevChild)
|
return t.normalizeNodeWith(schema, child, prevChild)
|
||||||
},
|
},
|
||||||
transform
|
transform
|
||||||
|
Reference in New Issue
Block a user