Преглед изворни кода

use new prop binding type indicator syntax

Evan You пре 10 година
родитељ
комит
de987d4e8a

+ 1 - 1
examples/modal/index.html

@@ -57,7 +57,7 @@
     <div id="app">
       <button id="show-modal" on-click="showModal = true">Show Modal</button>
       <!-- use the modal component, pass in the prop -->
-      <modal :show="@showModal">
+      <modal bind-show@="showModal">
         <!--
           you can use custom content here to overwrite
           default content

+ 18 - 14
src/compiler/compile-props.js

@@ -57,8 +57,16 @@ module.exports = function compileProps (el, propOptions) {
     if (value !== null) {
       el.removeAttribute(attr)
     } else {
+
       // then check dynamic version
-      value = prop.raw = _.getBindAttr(el, attr)
+      if ((value = _.getBindAttr(el, attr)) === null) {
+        if ((value = _.getBindAttr(el, attr + '@')) !== null) {
+          prop.mode = propBindingModes.TWO_WAY
+        } else if ((value = _.getBindAttr(el, attr + '*')) !== null) {
+          prop.mode = propBindingModes.ONE_TIME
+        }
+      }
+      prop.raw = value
       if (value !== null) {
         parsed = dirParser.parse(value)
         value = parsed.expression
@@ -71,19 +79,15 @@ module.exports = function compileProps (el, propOptions) {
           prop.optimizedLiteral = true
         } else {
           prop.dynamic = true
-          if (value.charAt(0) === '*') {
-            prop.mode = propBindingModes.ONE_TIME
-            value = value.slice(1).trim()
-          } else if (value.charAt(0) === '@') {
-            value = value.slice(1).trim()
-            if (settablePathRE.test(value)) {
-              prop.mode = propBindingModes.TWO_WAY
-            } else {
-              process.env.NODE_ENV !== 'production' && _.warn(
-                'Cannot bind two-way prop with non-settable ' +
-                'parent path: ' + value
-              )
-            }
+          // check non-settable path for two-way bindings
+          if (process.env.NODE_ENV !== 'production' &&
+              prop.mode === propBindingModes.TWO_WAY &&
+              !settablePathRE.test(value)) {
+            prop.mode = propBindingModes.ONE_WAY
+            _.warn(
+              'Cannot bind two-way prop with non-settable ' +
+              'parent path: ' + value
+            )
           }
         }
         prop.parentPath = value

+ 8 - 7
test/unit/specs/compiler/compile_spec.js

@@ -223,13 +223,14 @@ if (_.inBrowser) {
         { name: 'testOneTime' },
         { name: 'optimizeLiteral' }
       ]
-      el.setAttribute('bind-test-normal', 'a')
-      el.setAttribute('test-literal', '1')
-      el.setAttribute('bind-optimize-literal', '1')
-      el.setAttribute('bind-test-two-way', '@a')
-      el.setAttribute('bind-two-way-warn', '@a + 1')
-      el.setAttribute('bind-test-one-time', '*a')
-      compiler.compileAndLinkProps(vm, el, props)
+      el.innerHTML = '<div ' +
+        'bind-test-normal="a" ' +
+        'test-literal="1" ' +
+        'bind-optimize-literal="1" ' +
+        'bind-test-two-way@="a" ' +
+        'bind-two-way-warn@="a + 1" ' +
+        'bind-test-one-time*="a"></div>'
+      compiler.compileAndLinkProps(vm, el.firstChild, props)
       expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
       // literal
       expect(vm.testLiteral).toBe('1')

+ 4 - 4
test/unit/specs/directives/internal/prop_spec.js

@@ -73,7 +73,7 @@ if (_.inBrowser) {
             a: 'A'
           }
         },
-        template: '<test bind-testt="@test" bind-bb="@b" bind-a="@ test.a " ref="child"></test>',
+        template: '<test bind-testt@="test" bind-bb@="b" bind-a@=" test.a " ref="child"></test>',
         components: {
           test: {
             props: ['testt', 'bb', 'a'],
@@ -123,7 +123,7 @@ if (_.inBrowser) {
         data: {
           b: 'B'
         },
-        template: '<test bind-b="*b" ref="child"></test>',
+        template: '<test bind-b*="b" ref="child"></test>',
         components: {
           test: {
             props: ['b'],
@@ -145,7 +145,7 @@ if (_.inBrowser) {
         data: {
           b: 'B'
         },
-        template: '<test bind-b="@ b + \'B\'" ref="child"></test>',
+        template: '<test bind-b@=" b + \'B\'" ref="child"></test>',
         components: {
           test: {
             props: ['b'],
@@ -248,7 +248,7 @@ if (_.inBrowser) {
           a: 'A',
           b: 'B'
         },
-        template: '<test bind-aa="@a" bind-bb="b"></test>',
+        template: '<test bind-aa@="a" bind-bb="b"></test>',
         components: {
           test: {
             props: ['aa', 'bb'],

+ 1 - 1
test/unit/specs/util/component_spec.js

@@ -38,7 +38,7 @@ describe('Util - component', function () {
     el = document.createElement('test2')
     el.setAttribute('is', 'what')
     res = _.checkComponent(el, {
-        components: {}
+      components: {}
     })
     expect(res.id).toBe('what')
   })