1
0
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:
Ian Storm Taylor
2016-07-22 12:36:36 -07:00
parent 06c7e885f8
commit 3bc0664852

View File

@@ -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'