Skip to content

Commit 170e8dc

Browse files
kfuledead-claudia
authored andcommitted
refactor execSelector
This commit fully separates the normalization of `class` and `className` from the merging of `vnode.attrs` and `vnode.state.attrs`, which were previously handled together in the same code path. This simplifies conditional branches and improves bundle size and performance.
1 parent ca72c73 commit 170e8dc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

render/hyperscript.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,21 @@ function execSelector(state, vnode) {
5151
return vnode
5252
}
5353

54-
var hasClass = hasOwn.call(attrs, "class")
55-
var className = hasClass ? attrs.class : attrs.className
54+
if (hasOwn.call(attrs, "class")) {
55+
if (attrs.class != null) attrs.className = attrs.class
56+
attrs.class = null
57+
}
5658

5759
if (state.attrs !== emptyAttrs) {
60+
var className = attrs.className
5861
attrs = Object.assign({}, state.attrs, attrs)
5962

60-
if (className != null || state.attrs.className != null) attrs.className =
63+
if (state.attrs.className != null) attrs.className =
6164
className != null
62-
? state.attrs.className != null
63-
? String(state.attrs.className) + " " + String(className)
64-
: className
65+
? String(state.attrs.className) + " " + String(className)
6566
: state.attrs.className
66-
} else {
67-
if (className != null) attrs.className = className
6867
}
6968

70-
if (hasClass) attrs.class = null
71-
7269
// workaround for #2622 (reorder keys in attrs to set "type" first)
7370
// The DOM does things to inputs based on the "type", so it needs set first.
7471
// See: https://github.com/MithrilJS/mithril.js/issues/2622

0 commit comments

Comments
 (0)