mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Improve performances of "getPreviousSibling" and "getNextSibling" with memoization
This commit is contained in:
@@ -670,12 +670,16 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getNextSibling(key) {
|
getNextSibling(key) {
|
||||||
const node = this.assertDescendant(key)
|
key = Normalize.key(key)
|
||||||
return this
|
|
||||||
.getParent(node)
|
const parent = this.getParent(key)
|
||||||
.nodes
|
const after = parent.nodes
|
||||||
.skipUntil(child => child == node)
|
.skipUntil(child => child.key == key)
|
||||||
.get(1)
|
|
||||||
|
if (after.size == 0) {
|
||||||
|
throw new Error(`Could not find a child node with key "${key}".`)
|
||||||
|
}
|
||||||
|
return after.get(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -822,12 +826,16 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getPreviousSibling(key) {
|
getPreviousSibling(key) {
|
||||||
const node = this.assertDescendant(key)
|
key = Normalize.key(key)
|
||||||
return this
|
const parent = this.getParent(key)
|
||||||
.getParent(node)
|
const before = parent.nodes
|
||||||
.nodes
|
.takeUntil(child => child.key == key)
|
||||||
.takeUntil(child => child == node)
|
|
||||||
.last()
|
if (before.size == parent.nodes.size) {
|
||||||
|
throw new Error(`Could not find a child node with key "${key}".`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return before.last()
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user