Skip to content

Commit

Permalink
[refactor] render: move isFileInput into setAttr()
Browse files Browse the repository at this point in the history
The isFileInput is needed only when key is "value", so moving the logic into setAttr() would not increase time of calculation. Also, the code outlook improves a bit, of course.
  • Loading branch information
kfule committed Oct 26, 2024
1 parent f190a8b commit 98b7065
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,8 @@ module.exports = function() {

//attrs
function setAttrs(vnode, attrs, ns) {
var isFileInput = attrs != null && vnode.tag === "input" && attrs.type === "file"
for (var key in attrs) {
setAttr(vnode, key, null, attrs[key], ns, isFileInput)
setAttr(vnode, key, null, attrs[key], ns)
}
}
function setAttr(vnode, key, old, value, ns, isFileInput) {
Expand All @@ -685,6 +684,7 @@ module.exports = function() {
if (key === "value") {
// Only do the coercion if we're actually going to check the value.
/* eslint-disable no-implicit-coercion */
var isFileInput = vnode.tag === "input" && vnode.attrs.type === "file"
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
//setting input[type=file][value] to same value causes an error to be generated if it's non-empty
if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === "" + value && (isFileInput || vnode.dom === activeElement(vnode.dom))) return
Expand Down Expand Up @@ -747,9 +747,8 @@ module.exports = function() {
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
}
if (attrs != null) {
var isFileInput = vnode.tag === "input" && attrs.type === "file"
for (var key in attrs) {
setAttr(vnode, key, old && old[key], attrs[key], ns, isFileInput)
setAttr(vnode, key, old && old[key], attrs[key], ns)
}
}
var val
Expand Down

0 comments on commit 98b7065

Please sign in to comment.