mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 19:52:32 +02:00
Don't calcul range decorations in shouldComponentUpdate when schema has no decorations
This commit is contained in:
@@ -143,8 +143,9 @@ class Node extends React.Component {
|
|||||||
|
|
||||||
// For text nodes, which can have custom decorations, we need to check to
|
// For text nodes, which can have custom decorations, we need to check to
|
||||||
// see if the block has changed, which has caused the decorations to change.
|
// see if the block has changed, which has caused the decorations to change.
|
||||||
if (nextProps.node.kind == 'text') {
|
if (nextProps.node.kind == 'text' && nextProps.schema.hasDecorators) {
|
||||||
const { node, schema, state } = nextProps
|
const { node, schema, state } = nextProps
|
||||||
|
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const decorators = document.getDescendantDecorators(node.key, schema)
|
const decorators = document.getDescendantDecorators(node.key, schema)
|
||||||
const ranges = node.getRanges(decorators)
|
const ranges = node.getRanges(decorators)
|
||||||
@@ -155,7 +156,9 @@ class Node extends React.Component {
|
|||||||
const prevDecorators = prevDocument.getDescendantDecorators(prevNode.key, prevSchema)
|
const prevDecorators = prevDocument.getDescendantDecorators(prevNode.key, prevSchema)
|
||||||
const prevRanges = prevNode.getRanges(prevDecorators)
|
const prevRanges = prevNode.getRanges(prevDecorators)
|
||||||
|
|
||||||
if (!ranges.equals(prevRanges)) return true
|
if (!ranges.equals(prevRanges)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, don't update.
|
// Otherwise, don't update.
|
||||||
|
@@ -46,6 +46,8 @@ class Schema extends new Record(DEFAULTS) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if one rule can normalize the document
|
* Return true if one rule can normalize the document
|
||||||
|
*
|
||||||
|
* @return {Boolean} isNormalization
|
||||||
*/
|
*/
|
||||||
|
|
||||||
get isNormalization() {
|
get isNormalization() {
|
||||||
@@ -53,6 +55,17 @@ class Schema extends new Record(DEFAULTS) {
|
|||||||
return rules.some(rule => rule.validate)
|
return rules.some(rule => rule.validate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if one rule can decorate text nodes
|
||||||
|
*
|
||||||
|
* @return {Boolean} hasDecorators
|
||||||
|
*/
|
||||||
|
|
||||||
|
get hasDecorators() {
|
||||||
|
const { rules } = this
|
||||||
|
return rules.some(rule => rule.decorate)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the renderer for an `object`.
|
* Return the renderer for an `object`.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user