mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-24 02:27:37 +00:00
Decompose findParentNodeOfType
This commit is contained in:
parent
10a722f613
commit
3f7590817f
1 changed files with 9 additions and 3 deletions
|
|
@ -135,15 +135,21 @@ export function findInTree(node, predicate) {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Operations on trees
|
||||
export function findParentNodeOfType(node, type) {
|
||||
export function findParent(node, predicate) {
|
||||
let n = node;
|
||||
while (n.parent) {
|
||||
n = n.parent;
|
||||
if (type.has(n.name)) {
|
||||
if (predicate(n)) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Operations on trees
|
||||
export function findParentNodeOfType(node, type) {
|
||||
return findParent(node, node => type.has(node.name));
|
||||
}
|
||||
|
||||
export function findParentOrCurrentNodeOfType(node, type) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue