Evan You 9 лет назад
Родитель
Сommit
dc4f3aaf11

+ 12 - 6
src/platforms/web/runtime/modules/attrs.js

@@ -1,18 +1,24 @@
 /* @flow */
 /* @flow */
 
 
-import { extend } from 'shared/util'
 import { isIE9 } from 'core/util/env'
 import { isIE9 } from 'core/util/env'
+
+import {
+  extend,
+  isDef,
+  isUndef
+} from 'shared/util'
+
 import {
 import {
-  isBooleanAttr,
-  isEnumeratedAttr,
   isXlink,
   isXlink,
   xlinkNS,
   xlinkNS,
   getXlinkProp,
   getXlinkProp,
+  isBooleanAttr,
+  isEnumeratedAttr,
   isFalsyAttrValue
   isFalsyAttrValue
 } from 'web/util/index'
 } from 'web/util/index'
 
 
 function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
 function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
-  if (!oldVnode.data.attrs && !vnode.data.attrs) {
+  if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) {
     return
     return
   }
   }
   let key, cur, old
   let key, cur, old
@@ -20,7 +26,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
   const oldAttrs = oldVnode.data.attrs || {}
   const oldAttrs = oldVnode.data.attrs || {}
   let attrs: any = vnode.data.attrs || {}
   let attrs: any = vnode.data.attrs || {}
   // clone observed objects, as the user probably wants to mutate it
   // clone observed objects, as the user probably wants to mutate it
-  if (attrs.__ob__) {
+  if (isDef(attrs.__ob__)) {
     attrs = vnode.data.attrs = extend({}, attrs)
     attrs = vnode.data.attrs = extend({}, attrs)
   }
   }
 
 
@@ -37,7 +43,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
     setAttr(elm, 'value', attrs.value)
     setAttr(elm, 'value', attrs.value)
   }
   }
   for (key in oldAttrs) {
   for (key in oldAttrs) {
-    if (attrs[key] == null) {
+    if (isUndef(attrs[key])) {
       if (isXlink(key)) {
       if (isXlink(key)) {
         elm.removeAttributeNS(xlinkNS, getXlinkProp(key))
         elm.removeAttributeNS(xlinkNS, getXlinkProp(key))
       } else if (!isEnumeratedAttr(key)) {
       } else if (!isEnumeratedAttr(key)) {

+ 20 - 4
src/platforms/web/runtime/modules/class.js

@@ -1,13 +1,29 @@
 /* @flow */
 /* @flow */
 
 
-import { genClassForVnode, concat, stringifyClass } from 'web/util/index'
+import {
+  isDef,
+  isUndef
+} from 'shared/util'
+
+import {
+  concat,
+  stringifyClass,
+  genClassForVnode
+} from 'web/util/index'
 
 
 function updateClass (oldVnode: any, vnode: any) {
 function updateClass (oldVnode: any, vnode: any) {
   const el = vnode.elm
   const el = vnode.elm
   const data: VNodeData = vnode.data
   const data: VNodeData = vnode.data
   const oldData: VNodeData = oldVnode.data
   const oldData: VNodeData = oldVnode.data
-  if (!data.staticClass && !data.class &&
-      (!oldData || (!oldData.staticClass && !oldData.class))) {
+  if (
+    isUndef(data.staticClass) &&
+    isUndef(data.class) && (
+      isUndef(oldData) || (
+        isUndef(oldData.staticClass) &&
+        isUndef(oldData.class)
+      )
+    )
+  ) {
     return
     return
   }
   }
 
 
@@ -15,7 +31,7 @@ function updateClass (oldVnode: any, vnode: any) {
 
 
   // handle transition classes
   // handle transition classes
   const transitionClass = el._transitionClasses
   const transitionClass = el._transitionClasses
-  if (transitionClass) {
+  if (isDef(transitionClass)) {
     cls = concat(cls, stringifyClass(transitionClass))
     cls = concat(cls, stringifyClass(transitionClass))
   }
   }
 
 

+ 6 - 6
src/platforms/web/runtime/modules/dom-props.js

@@ -1,9 +1,9 @@
 /* @flow */
 /* @flow */
 
 
-import { extend, toNumber } from 'shared/util'
+import { isDef, isUndef, extend, toNumber } from 'shared/util'
 
 
 function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
 function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
-  if (!oldVnode.data.domProps && !vnode.data.domProps) {
+  if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {
     return
     return
   }
   }
   let key, cur
   let key, cur
@@ -11,12 +11,12 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
   const oldProps = oldVnode.data.domProps || {}
   const oldProps = oldVnode.data.domProps || {}
   let props = vnode.data.domProps || {}
   let props = vnode.data.domProps || {}
   // clone observed objects, as the user probably wants to mutate it
   // clone observed objects, as the user probably wants to mutate it
-  if (props.__ob__) {
+  if (isDef(props.__ob__)) {
     props = vnode.data.domProps = extend({}, props)
     props = vnode.data.domProps = extend({}, props)
   }
   }
 
 
   for (key in oldProps) {
   for (key in oldProps) {
-    if (props[key] == null) {
+    if (isUndef(props[key])) {
       elm[key] = ''
       elm[key] = ''
     }
     }
   }
   }
@@ -68,10 +68,10 @@ function isDirty (elm: acceptValueElm, checkVal: string): boolean {
 function isInputChanged (elm: any, newVal: string): boolean {
 function isInputChanged (elm: any, newVal: string): boolean {
   const value = elm.value
   const value = elm.value
   const modifiers = elm._vModifiers // injected by v-model runtime
   const modifiers = elm._vModifiers // injected by v-model runtime
-  if ((modifiers && modifiers.number) || elm.type === 'number') {
+  if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') {
     return toNumber(value) !== toNumber(newVal)
     return toNumber(value) !== toNumber(newVal)
   }
   }
-  if (modifiers && modifiers.trim) {
+  if (isDef(modifiers) && modifiers.trim) {
     return value.trim() !== newVal.trim()
     return value.trim() !== newVal.trim()
   }
   }
   return value !== newVal
   return value !== newVal

+ 12 - 5
src/platforms/web/runtime/modules/events.js

@@ -1,7 +1,8 @@
 /* @flow */
 /* @flow */
 
 
-import { isChrome, isIE, supportsPassive } from 'core/util/env'
+import { isDef, isUndef } from 'shared/util'
 import { updateListeners } from 'core/vdom/helpers/index'
 import { updateListeners } from 'core/vdom/helpers/index'
+import { isChrome, isIE, supportsPassive } from 'core/util/env'
 import { RANGE_TOKEN, CHECKBOX_RADIO_TOKEN } from 'web/compiler/directives/model'
 import { RANGE_TOKEN, CHECKBOX_RADIO_TOKEN } from 'web/compiler/directives/model'
 
 
 // normalize v-model event tokens that can only be determined at runtime.
 // normalize v-model event tokens that can only be determined at runtime.
@@ -11,13 +12,13 @@ import { RANGE_TOKEN, CHECKBOX_RADIO_TOKEN } from 'web/compiler/directives/model
 function normalizeEvents (on) {
 function normalizeEvents (on) {
   let event
   let event
   /* istanbul ignore if */
   /* istanbul ignore if */
-  if (on[RANGE_TOKEN]) {
+  if (isDef(on[RANGE_TOKEN])) {
     // IE input[type=range] only supports `change` event
     // IE input[type=range] only supports `change` event
     event = isIE ? 'change' : 'input'
     event = isIE ? 'change' : 'input'
     on[event] = [].concat(on[RANGE_TOKEN], on[event] || [])
     on[event] = [].concat(on[RANGE_TOKEN], on[event] || [])
     delete on[RANGE_TOKEN]
     delete on[RANGE_TOKEN]
   }
   }
-  if (on[CHECKBOX_RADIO_TOKEN]) {
+  if (isDef(on[CHECKBOX_RADIO_TOKEN])) {
     // Chrome fires microtasks in between click/change, leads to #4521
     // Chrome fires microtasks in between click/change, leads to #4521
     event = isChrome ? 'click' : 'change'
     event = isChrome ? 'click' : 'change'
     on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || [])
     on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || [])
@@ -46,7 +47,13 @@ function add (
       }
       }
     }
     }
   }
   }
-  target.addEventListener(event, handler, supportsPassive ? { capture, passive } : capture)
+  target.addEventListener(
+    event,
+    handler,
+    supportsPassive
+      ? { capture, passive }
+      : capture
+  )
 }
 }
 
 
 function remove (
 function remove (
@@ -59,7 +66,7 @@ function remove (
 }
 }
 
 
 function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
 function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
-  if (!oldVnode.data.on && !vnode.data.on) {
+  if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) {
     return
     return
   }
   }
   const on = vnode.data.on || {}
   const on = vnode.data.on || {}

+ 6 - 6
src/platforms/web/runtime/modules/style.js

@@ -1,7 +1,7 @@
 /* @flow */
 /* @flow */
 
 
-import { cached, camelize, extend } from 'shared/util'
-import { normalizeStyleBinding, getStyle } from 'web/util/style'
+import { getStyle, normalizeStyleBinding } from 'web/util/style'
+import { cached, camelize, extend, isDef, isUndef } from 'shared/util'
 
 
 const cssVarRE = /^--/
 const cssVarRE = /^--/
 const importantRE = /\s*!important$/
 const importantRE = /\s*!important$/
@@ -38,8 +38,8 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
   const data = vnode.data
   const data = vnode.data
   const oldData = oldVnode.data
   const oldData = oldVnode.data
 
 
-  if (!data.staticStyle && !data.style &&
-      !oldData.staticStyle && !oldData.style) {
+  if (isUndef(data.staticStyle) && isUndef(data.style) &&
+      isUndef(oldData.staticStyle) && isUndef(oldData.style)) {
     return
     return
   }
   }
 
 
@@ -56,14 +56,14 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
   // store normalized style under a different key for next diff
   // store normalized style under a different key for next diff
   // make sure to clone it if it's reactive, since the user likley wants
   // make sure to clone it if it's reactive, since the user likley wants
   // to mutate it.
   // to mutate it.
-  vnode.data.normalizedStyle = style.__ob__
+  vnode.data.normalizedStyle = isDef(style.__ob__)
     ? extend({}, style)
     ? extend({}, style)
     : style
     : style
 
 
   const newStyle = getStyle(vnode, true)
   const newStyle = getStyle(vnode, true)
 
 
   for (name in oldStyle) {
   for (name in oldStyle) {
-    if (newStyle[name] == null) {
+    if (isUndef(newStyle[name])) {
       setProp(el, name, '')
       setProp(el, name, '')
     }
     }
   }
   }

+ 22 - 13
src/platforms/web/runtime/modules/transition.js

@@ -1,10 +1,17 @@
 /* @flow */
 /* @flow */
 
 
-import { once, isObject, toNumber } from 'shared/util'
 import { inBrowser, isIE9, warn } from 'core/util/index'
 import { inBrowser, isIE9, warn } from 'core/util/index'
 import { mergeVNodeHook } from 'core/vdom/helpers/index'
 import { mergeVNodeHook } from 'core/vdom/helpers/index'
 import { activeInstance } from 'core/instance/lifecycle'
 import { activeInstance } from 'core/instance/lifecycle'
 
 
+import {
+  once,
+  isDef,
+  isUndef,
+  isObject,
+  toNumber
+} from 'shared/util'
+
 import {
 import {
   nextFrame,
   nextFrame,
   resolveTransition,
   resolveTransition,
@@ -17,18 +24,18 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
   const el: any = vnode.elm
   const el: any = vnode.elm
 
 
   // call leave callback now
   // call leave callback now
-  if (el._leaveCb) {
+  if (isDef(el._leaveCb)) {
     el._leaveCb.cancelled = true
     el._leaveCb.cancelled = true
     el._leaveCb()
     el._leaveCb()
   }
   }
 
 
   const data = resolveTransition(vnode.data.transition)
   const data = resolveTransition(vnode.data.transition)
-  if (!data) {
+  if (isUndef(data)) {
     return
     return
   }
   }
 
 
   /* istanbul ignore if */
   /* istanbul ignore if */
-  if (el._enterCb || el.nodeType !== 1) {
+  if (isDef(el._enterCb) || el.nodeType !== 1) {
     return
     return
   }
   }
 
 
@@ -50,7 +57,7 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
     afterAppear,
     afterAppear,
     appearCancelled,
     appearCancelled,
     duration
     duration
-  } = data
+  } = (data: any)
 
 
   // activeInstance will always be the <transition> component managing this
   // activeInstance will always be the <transition> component managing this
   // transition. One edge case to check is when the <transition> is placed
   // transition. One edge case to check is when the <transition> is placed
@@ -167,18 +174,18 @@ export function leave (vnode: VNodeWithData, rm: Function) {
   const el: any = vnode.elm
   const el: any = vnode.elm
 
 
   // call enter callback now
   // call enter callback now
-  if (el._enterCb) {
+  if (isDef(el._enterCb)) {
     el._enterCb.cancelled = true
     el._enterCb.cancelled = true
     el._enterCb()
     el._enterCb()
   }
   }
 
 
   const data = resolveTransition(vnode.data.transition)
   const data = resolveTransition(vnode.data.transition)
-  if (!data) {
+  if (isUndef(data)) {
     return rm()
     return rm()
   }
   }
 
 
   /* istanbul ignore if */
   /* istanbul ignore if */
-  if (el._leaveCb || el.nodeType !== 1) {
+  if (isDef(el._leaveCb) || el.nodeType !== 1) {
     return
     return
   }
   }
 
 
@@ -194,7 +201,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
     leaveCancelled,
     leaveCancelled,
     delayLeave,
     delayLeave,
     duration
     duration
-  } = data
+  } = (data: any)
 
 
   const expectsCSS = css !== false && !isIE9
   const expectsCSS = css !== false && !isIE9
   const userWantsControl = getHookArgumentsLength(leave)
   const userWantsControl = getHookArgumentsLength(leave)
@@ -295,9 +302,11 @@ function isValidDuration (val) {
  * - a plain function (.length)
  * - a plain function (.length)
  */
  */
 function getHookArgumentsLength (fn: Function): boolean {
 function getHookArgumentsLength (fn: Function): boolean {
-  if (!fn) return false
+  if (isUndef(fn)) {
+    return false
+  }
   const invokerFns = fn.fns
   const invokerFns = fn.fns
-  if (invokerFns) {
+  if (isDef(invokerFns)) {
     // invoker
     // invoker
     return getHookArgumentsLength(
     return getHookArgumentsLength(
       Array.isArray(invokerFns)
       Array.isArray(invokerFns)
@@ -310,7 +319,7 @@ function getHookArgumentsLength (fn: Function): boolean {
 }
 }
 
 
 function _enter (_: any, vnode: VNodeWithData) {
 function _enter (_: any, vnode: VNodeWithData) {
-  if (!vnode.data.show) {
+  if (vnode.data.show !== true) {
     enter(vnode)
     enter(vnode)
   }
   }
 }
 }
@@ -320,7 +329,7 @@ export default inBrowser ? {
   activate: _enter,
   activate: _enter,
   remove (vnode: VNode, rm: Function) {
   remove (vnode: VNode, rm: Function) {
     /* istanbul ignore else */
     /* istanbul ignore else */
-    if (!vnode.data.show) {
+    if (vnode.data.show !== true) {
       leave(vnode, rm)
       leave(vnode, rm)
     } else {
     } else {
       rm()
       rm()