1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-02 11:42:53 +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 let { characters, cache } = this
if (characters == cache) return this if (characters == cache) return this
const decorations = decorator(this) const decorations = this.getDecoratedCharacters(decorator)
if (decorations == characters) return this if (decorations == characters) return this
return this.merge({ 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. * Get the decorated characters grouped by marks.
* *
* @return {List} * @return {List} ranges
*/ */
getDecoratedRanges() { getDecoratedRanges() {
@@ -125,7 +135,7 @@ class Text extends new Record(DEFAULTS) {
/** /**
* Get the characters grouped by marks. * Get the characters grouped by marks.
* *
* @return {List} * @return {List} ranges
*/ */
getRanges() { getRanges() {
@@ -234,6 +244,7 @@ class Text extends new Record(DEFAULTS) {
*/ */
memoize(Text.prototype, [ memoize(Text.prototype, [
'getDecoratedCharacters',
'getDecoratedRanges', 'getDecoratedRanges',
'getRanges', 'getRanges',
'getRangesForCharacters' 'getRangesForCharacters'