Skip to content

Commit fdf06e0

Browse files
author
Steven Silvester
authored
Merge pull request #36 from telamonian/improve-passthru-attr-handling
Improve handling of attributes for hpass virtualdom elements
2 parents a1fe949 + 5af0951 commit fdf06e0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

packages/virtualdom/src/index.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,8 @@ export function hpass(tag: string): VirtualElementPass {
10311031
} else if (arguments.length === 3) {
10321032
attrs = arguments[1];
10331033
renderer = arguments[2];
1034+
} else if (arguments.length > 3) {
1035+
throw new Error("hpass() should be called with 1, 2, or 3 arguments");
10341036
}
10351037

10361038
return new VirtualElementPass(tag, attrs, renderer);
@@ -1201,23 +1203,15 @@ namespace Private {
12011203
continue;
12021204
}
12031205

1204-
// Handle the case of passthru update.
1205-
if (oldVNode.type === 'passthru' && newVNode.type === 'passthru') {
1206-
newVNode.render(currElem as HTMLElement);
1207-
currElem = currElem!.nextSibling;
1208-
continue;
1209-
}
1210-
12111206
// If the types of the old and new nodes differ,
12121207
// create and insert a new node.
1213-
if (oldVNode.type === 'text' || newVNode.type === 'text' ||
1214-
oldVNode.type === 'passthru' || newVNode.type === 'passthru') {
1208+
if (oldVNode.type !== newVNode.type || oldVNode.type === 'text' || newVNode.type === 'text') {
12151209
ArrayExt.insert(oldCopy, i, newVNode);
12161210
createDOMNode(newVNode, host, currElem);
12171211
continue;
12181212
}
12191213

1220-
// At this point, both nodes are known to be element nodes.
1214+
// At this point, both nodes are known to be of matching non-text type.
12211215

12221216
// If the new elem is keyed, move an old keyed elem to the proper
12231217
// location before proceeding with the diff. The search can start
@@ -1263,7 +1257,11 @@ namespace Private {
12631257
updateAttrs(currElem as HTMLElement, oldVNode.attrs, newVNode.attrs);
12641258

12651259
// Update the element content.
1266-
updateContent(currElem as HTMLElement, oldVNode.children, newVNode.children);
1260+
if (oldVNode.type === 'passthru' || newVNode.type === 'passthru') {
1261+
(newVNode as VirtualElementPass).render(currElem as HTMLElement);
1262+
} else {
1263+
updateContent(currElem as HTMLElement, oldVNode.children, newVNode.children);
1264+
}
12671265

12681266
// Step to the next sibling element.
12691267
currElem = currElem!.nextSibling;

packages/widgets/src/tabbar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,9 @@ namespace TabBar {
13441344
let className = this.createIconClass(data);
13451345

13461346
if (title.iconRenderer) {
1347-
return hpass('div', title.iconRenderer);
1347+
return hpass('div', {className, title: title.iconLabel}, title.iconRenderer);
13481348
} else {
1349-
return h.div({className}, data.title.iconLabel);
1349+
return h.div({className}, title.iconLabel);
13501350
}
13511351
}
13521352

0 commit comments

Comments
 (0)