Explorar el Código

rename vnode.data.props -> domProps

Evan You hace 9 años
padre
commit
69ecdcb05e

+ 1 - 0
flow/vnode.js

@@ -41,6 +41,7 @@ declare interface VNodeData {
   show?: true;
   props?: { [key: string]: any };
   attrs?: { [key: string]: string };
+  domProps?: { [key: string]: any };
   staticAttrs?: { [key: string]: string };
   hook?: { [key: string]: Function };
   on?: { [key: string]: Function | Array<Function> };

+ 4 - 4
src/compiler/codegen.js

@@ -146,10 +146,6 @@ function genData (el: ASTElement): string | void {
   if (el.attrsMap['v-show']) {
     data += 'show:true,'
   }
-  // props
-  if (el.props) {
-    data += `props:{${genProps(el.props)}},`
-  }
   // attributes
   if (el.attrs) {
     data += `attrs:{${genProps(el.attrs)}},`
@@ -158,6 +154,10 @@ function genData (el: ASTElement): string | void {
   if (el.staticAttrs) {
     data += `staticAttrs:{${genProps(el.staticAttrs)}},`
   }
+  // DOM props
+  if (el.props) {
+    data += `domProps:{${genProps(el.props)}},`
+  }
   // hooks
   if (el.hooks) {
     data += `hook:{${genHooks(el.hooks)}},`

+ 1 - 1
src/core/instance/render.js

@@ -162,7 +162,7 @@ export function renderMixin (Vue: Class<Component>) {
         const data = vnode.data
         for (const key in value) {
           const hash = config.mustUseProp(key)
-            ? data.props || (data.props = {})
+            ? data.domProps || (data.domProps = {})
             : data.attrs || (data.attrs = {})
           hash[key] = value[key]
         }

+ 3 - 4
src/core/vdom/create-component.js

@@ -222,16 +222,15 @@ function extractProps (data: VNodeData, Ctor: Class<Component>): ?Object {
     return
   }
   const res = {}
-  const attrs = data.attrs
-  const props = data.props
-  const staticAttrs = data.staticAttrs
-  if (!attrs && !props && !staticAttrs) {
+  const { attrs, props, domProps, staticAttrs } = data
+  if (!attrs && !props && !domProps && !staticAttrs) {
     return res
   }
   for (const key in propOptions) {
     const altKey = hyphenate(key)
     checkProp(res, attrs, key, altKey) ||
     checkProp(res, props, key, altKey) ||
+    checkProp(res, domProps, key, altKey) ||
     checkProp(res, staticAttrs, key, altKey)
   }
   return res

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

@@ -1,14 +1,14 @@
 /* @flow */
 
-function updateProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
-  if (!oldVnode.data.props && !vnode.data.props) {
+function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
+  if (!oldVnode.data.domProps && !vnode.data.domProps) {
     return
   }
   let key, cur
   const elm: any = vnode.elm
-  const oldProps = oldVnode.data.props || {}
-  const props = vnode.data.props || {}
-  const clonedProps = vnode.data.props = {}
+  const oldProps = oldVnode.data.domProps || {}
+  const props = vnode.data.domProps || {}
+  const clonedProps = vnode.data.domProps = {}
 
   for (key in oldProps) {
     if (props[key] == null) {
@@ -32,6 +32,6 @@ function updateProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
 }
 
 export default {
-  create: updateProps,
-  update: updateProps
+  create: updateDOMProps,
+  update: updateDOMProps
 }

+ 2 - 2
src/platforms/web/runtime/modules/index.js

@@ -1,7 +1,7 @@
 import attrs from './attrs'
 import klass from './class'
 import events from './events'
-import props from './props'
+import domProps from './dom-props'
 import style from './style'
 import transition from './transition'
 
@@ -9,7 +9,7 @@ export default [
   attrs,
   klass,
   events,
-  props,
+  domProps,
   style,
   transition
 ]

+ 1 - 1
src/platforms/web/server/modules/props.js → src/platforms/web/server/modules/dom-props.js

@@ -5,7 +5,7 @@ import { renderAttr } from './attrs'
 import { propsToAttrMap, isRenderableAttr } from 'web/util/attrs'
 
 export default function (node: VNodeWithData): string {
-  const props = node.data.props
+  const props = node.data.domProps
   let res = ''
   if (props) {
     for (const key in props) {

+ 2 - 2
src/platforms/web/server/modules/index.js

@@ -1,11 +1,11 @@
 import attrs from './attrs'
-import props from './props'
+import domProps from './dom-props'
 import klass from './class'
 import style from './style'
 
 export default [
   attrs,
-  props,
+  domProps,
   klass,
   style
 ]

+ 2 - 2
test/unit/modules/compiler/codegen.spec.js

@@ -153,10 +153,10 @@ describe('codegen', () => {
     )
   })
 
-  it('generate props with v-bind directive', () => {
+  it('generate DOM props with v-bind directive', () => {
     assertCodegen(
       '<p :value="msg">',
-      `with(this){return _h('p',{props:{"value":msg}})}`
+      `with(this){return _h('p',{domProps:{"value":msg}})}`
     )
   })
 

+ 9 - 9
test/unit/modules/vdom/modules/props.spec.js

@@ -1,24 +1,24 @@
 import { patch } from 'web/runtime/patch'
 import VNode from 'core/vdom/vnode'
 
-describe('vdom props module', () => {
-  it('should create an element with props', () => {
-    const vnode = new VNode('a', { props: { src: 'http://localhost/' }})
+describe('vdom domProps module', () => {
+  it('should create an element with domProps', () => {
+    const vnode = new VNode('a', { domProps: { src: 'http://localhost/' }})
     const elm = patch(null, vnode)
     expect(elm.src).toBe('http://localhost/')
   })
 
-  it('should change the elements props', () => {
-    const vnode1 = new VNode('a', { props: { src: 'http://localhost/' }})
-    const vnode2 = new VNode('a', { props: { src: 'http://vuejs.org/' }})
+  it('should change the elements domProps', () => {
+    const vnode1 = new VNode('a', { domProps: { src: 'http://localhost/' }})
+    const vnode2 = new VNode('a', { domProps: { src: 'http://vuejs.org/' }})
     patch(null, vnode1)
     const elm = patch(vnode1, vnode2)
     expect(elm.src).toBe('http://vuejs.org/')
   })
 
-  it('should remove the elements props', () => {
-    const vnode1 = new VNode('a', { props: { src: 'http://localhost/' }})
-    const vnode2 = new VNode('a', { props: {}})
+  it('should remove the elements domProps', () => {
+    const vnode1 = new VNode('a', { domProps: { src: 'http://localhost/' }})
+    const vnode2 = new VNode('a', { domProps: {}})
     patch(null, vnode1)
     const elm = patch(vnode1, vnode2)
     expect(elm.src).toBeUndefined()

+ 2 - 2
test/unit/modules/vdom/patch/hydration.spec.js

@@ -50,8 +50,8 @@ describe('hydration', () => {
     traverseAndAssert(vnode1, node0)
 
     // check update
-    const vnode2 = new VNode('div', { props: { id: 'foo' }}, [
-      new VNode('span', { props: { id: 'bar' }}),
+    const vnode2 = new VNode('div', { attrs: { id: 'foo' }}, [
+      new VNode('span', { attrs: { id: 'bar' }}),
       new VNode('div', { hook: { init }}, [
         new VNode('span', {}),
         new VNode('span', {})