Skip to content

Commit 7a797ea

Browse files
committed
Implement VDom.getById() and optimize component.Base#onScrollCapture() #8140
1 parent 4c321b1 commit 7a797ea

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/component/Base.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,11 +1434,11 @@ class Component extends Abstract {
14341434
let me = this;
14351435

14361436
if (me._vdom) {
1437-
let vdomNode = VDomUtil.find(me._vdom, data.target.id);
1437+
let vdomNode = VDomUtil.getById(me._vdom, data.target.id);
14381438

1439-
if (vdomNode && vdomNode.vdom) {
1440-
vdomNode.vdom.scrollTop = data.scrollTop;
1441-
vdomNode.vdom.scrollLeft = data.scrollLeft
1439+
if (vdomNode) {
1440+
vdomNode.scrollTop = data.scrollTop;
1441+
vdomNode.scrollLeft = data.scrollLeft
14421442
}
14431443
}
14441444
}

src/util/VDom.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,41 @@ class VDom extends Base {
143143
return VDom.find(vdom, {flag})?.vdom
144144
}
145145

146+
/**
147+
* Finds a child vdom node inside a vdom tree by a given id
148+
* @param {Object} vdom
149+
* @param {String|null} id
150+
* @returns {Object|null} child vdom node or null
151+
*/
152+
static getById(vdom, id) {
153+
vdom = VDom.getVdom(vdom);
154+
155+
let childNodes = vdom.cn || [],
156+
i = 0,
157+
len = childNodes.length,
158+
childNode;
159+
160+
if (vdom.id === id) {
161+
return vdom
162+
}
163+
164+
for (; i < len; i++) {
165+
childNode = VDom.getVdom(childNodes[i]);
166+
167+
if (childNode.id === id) {
168+
return childNode
169+
}
170+
171+
childNode = VDom.getById(childNode, id);
172+
173+
if (childNode) {
174+
return childNode
175+
}
176+
}
177+
178+
return null
179+
}
180+
146181
/**
147182
* Get the ids of all child nodes of the given vdom tree
148183
* @param vdom

0 commit comments

Comments
 (0)