]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: avoid unnecessary style normalization
authorEvan You <yyx990803@gmail.com>
Thu, 20 Sep 2018 06:17:52 +0000 (02:17 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 20 Sep 2018 06:17:52 +0000 (02:17 -0400)
packages/renderer-dom/src/modules/style.ts

index 1652949d44b1a0bca5e0c807652f30b370c56e2f..f97df183ea4fc44dcb49d37537bd2cd889de9ceb 100644 (file)
@@ -4,12 +4,6 @@ import { isObservable } from '@vue/core'
 const nonNumericRE = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i
 
 export function patchStyle(el: any, prev: any, next: any, data: any) {
-  // If next is observed, the user is likely to mutate the style object.
-  // We need to normalize + clone it and replace data.style with the clone.
-  if (isObservable(next)) {
-    data.style = normalizeStyle(next)
-  }
-
   const { style } = el
   if (!next) {
     el.removeAttribute('style')
@@ -17,9 +11,14 @@ export function patchStyle(el: any, prev: any, next: any, data: any) {
     style.cssText = next
   } else {
     // TODO: warn invalid value in dev
-    next = normalizeStyle(next)
-    for (const key in next) {
-      let value = next[key]
+    const normalizedNext: any = normalizeStyle(next)
+    // If next is observed, the user is likely to mutate the style object.
+    // We need to replace data.style with the normalized clone.
+    if (isObservable(next)) {
+      data.style = normalizedNext
+    }
+    for (const key in normalizedNext) {
+      let value = normalizedNext[key]
       if (typeof value === 'number' && !nonNumericRE.test(key)) {
         value = value + 'px'
       }
@@ -28,7 +27,7 @@ export function patchStyle(el: any, prev: any, next: any, data: any) {
     if (prev && typeof prev !== 'string') {
       prev = normalizeStyle(prev)
       for (const key in prev) {
-        if (!next[key]) {
+        if (!normalizedNext[key]) {
           style.setProperty(key, '')
         }
       }