1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 05:31:56 +02:00

Greatly improve performance of normalizeChildrenWith

This commit is contained in:
Soreine
2016-11-07 18:18:33 +01:00
parent b54ddf10ce
commit 83fa16d451

View File

@@ -1,6 +1,7 @@
import warning from '../utils/warning'
import { default as defaultSchema } from '../plugins/schema'
import Normalize from '../utils/normalize'
import { Map } from 'immutable'
// Maximum recursive calls for normalization
const MAX_CALLS = 50
@@ -40,9 +41,13 @@ function _normalizeChildrenWith(transform, schema, node, prevNode) {
return transform
}
const prevChildrenMap = new Map().withMutations(map => {
if (prevNode) prevNode.nodes.forEach(n => map.set(n.key, n))
})
return node.nodes.reduce(
(t, child) => {
const prevChild = prevNode ? prevNode.getChild(child.key) : null
const prevChild = prevChildrenMap.get(child.key)
return t.normalizeNodeWith(schema, child, prevChild)
},
transform