mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 19:22:35 +02:00
Small optimization for normalize
Avoid calling refreshNode needlessly
This commit is contained in:
@@ -105,11 +105,19 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
|
|||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For performance considerations, we will check if the transform was changed
|
||||||
|
const opCount = transform.operations.length
|
||||||
|
|
||||||
// Iterate over its children
|
// Iterate over its children
|
||||||
transform = _normalizeChildrenWith(transform, schema, node, prevNode)
|
transform = _normalizeChildrenWith(transform, schema, node, prevNode)
|
||||||
|
|
||||||
// Refresh the node reference, and normalize it
|
const hasChanged = transform.operations.length != opCount
|
||||||
node = _refreshNode(transform, node)
|
if (hasChanged) {
|
||||||
|
// Refresh the node reference
|
||||||
|
node = _refreshNode(transform, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now normalize the node itself if it still exist
|
||||||
if (node) {
|
if (node) {
|
||||||
transform = _normalizeNodeWith(transform, schema, node)
|
transform = _normalizeNodeWith(transform, schema, node)
|
||||||
}
|
}
|
||||||
@@ -160,8 +168,8 @@ export function normalizeWith(transform, schema, prevDocument) {
|
|||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document } = state
|
const { document } = state
|
||||||
|
|
||||||
// Schema was not rule to edit the document
|
|
||||||
if (!schema.isNormalization) {
|
if (!schema.isNormalization) {
|
||||||
|
// Schema has no normalization rules
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user