1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

Don't calcul range decorations in shouldComponentUpdate when schema has no decorations

This commit is contained in:
Samy Pessé
2016-11-02 16:43:29 +01:00
parent 0dc3c4ef8a
commit a74fbd1390
2 changed files with 18 additions and 2 deletions

View File

@@ -143,8 +143,9 @@ class Node extends React.Component {
// 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.
if (nextProps.node.kind == 'text') {
if (nextProps.node.kind == 'text' && nextProps.schema.hasDecorators) {
const { node, schema, state } = nextProps
const { document } = state
const decorators = document.getDescendantDecorators(node.key, schema)
const ranges = node.getRanges(decorators)
@@ -155,7 +156,9 @@ class Node extends React.Component {
const prevDecorators = prevDocument.getDescendantDecorators(prevNode.key, prevSchema)
const prevRanges = prevNode.getRanges(prevDecorators)
if (!ranges.equals(prevRanges)) return true
if (!ranges.equals(prevRanges)) {
return true
}
}
// Otherwise, don't update.

View File

@@ -46,6 +46,8 @@ class Schema extends new Record(DEFAULTS) {
/**
* Return true if one rule can normalize the document
*
* @return {Boolean} isNormalization
*/
get isNormalization() {
@@ -53,6 +55,17 @@ class Schema extends new Record(DEFAULTS) {
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`.
*