mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +02:00
refactor text model to memoize decorations
This commit is contained in:
@@ -103,7 +103,7 @@ class Text extends new Record(DEFAULTS) {
|
||||
let { characters, cache } = this
|
||||
if (characters == cache) return this
|
||||
|
||||
const decorations = decorator(this)
|
||||
const decorations = this.getDecoratedCharacters(decorator)
|
||||
if (decorations == characters) return this
|
||||
|
||||
return this.merge({
|
||||
@@ -112,10 +112,20 @@ class Text extends new Record(DEFAULTS) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorated characters.
|
||||
*
|
||||
* @return {List} characters
|
||||
*/
|
||||
|
||||
getDecoratedCharacters(decorator) {
|
||||
return decorator(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorated characters grouped by marks.
|
||||
*
|
||||
* @return {List}
|
||||
* @return {List} ranges
|
||||
*/
|
||||
|
||||
getDecoratedRanges() {
|
||||
@@ -125,7 +135,7 @@ class Text extends new Record(DEFAULTS) {
|
||||
/**
|
||||
* Get the characters grouped by marks.
|
||||
*
|
||||
* @return {List}
|
||||
* @return {List} ranges
|
||||
*/
|
||||
|
||||
getRanges() {
|
||||
@@ -234,6 +244,7 @@ class Text extends new Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
memoize(Text.prototype, [
|
||||
'getDecoratedCharacters',
|
||||
'getDecoratedRanges',
|
||||
'getRanges',
|
||||
'getRangesForCharacters'
|
||||
|
Reference in New Issue
Block a user