From 98b7065a28ae758e3e45ccd240015cff3f320c87 Mon Sep 17 00:00:00 2001 From: kfule Date: Sun, 27 Oct 2024 00:27:35 +0900 Subject: [PATCH] [refactor] render: move isFileInput into setAttr() 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. --- render/render.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/render/render.js b/render/render.js index 1f6ca3d7f..578974cdd 100644 --- a/render/render.js +++ b/render/render.js @@ -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) { @@ -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 @@ -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