1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 10:51:44 +02:00

Memoize schema validation

This commit is contained in:
Soreine
2016-11-14 11:54:59 +01:00
committed by Nicolas Gaborit
parent 56c2df067c
commit e868d44af4
3 changed files with 30 additions and 3 deletions

View File

@@ -1407,7 +1407,19 @@ const Node = {
} else {
return result
}
},
/**
* Validate the node against a `schema`.
*
* @param {Schema} schema
* @return {Object || Void}
*/
validate(schema) {
return schema.__validate(this)
}
}
/**
@@ -1452,7 +1464,8 @@ memoize(Node, [
'_getTexts',
'getTextsAtRange',
'hasVoidParent',
'isInlineSplitAtRange'
'isInlineSplitAtRange',
'validate'
])
/**

View File

@@ -329,6 +329,18 @@ class Text extends new Record(DEFAULTS) {
return this.merge({ characters })
}
/**
* Validate the text node against a `schema`.
*
* @param {Schema} schema
* @return {Object || Void}
*/
validate(schema) {
return schema.__validate(this)
}
}
/**
@@ -338,7 +350,8 @@ class Text extends new Record(DEFAULTS) {
memoize(Text.prototype, [
'getDecorations',
'getDecorators',
'getRanges'
'getRanges',
'validate'
])
/**

View File

@@ -233,7 +233,8 @@ function normalizeNodeOnly(transform, schema, node) {
// Auxiliary function, called recursively, with a maximum calls safety net.
function _recur(_transform, _node) {
const failure = schema.__validate(_node)
// _node.validate should be memoized
const failure = _node.validate(schema)
// Node is valid?
if (!failure) {