Evan You 12 년 전
부모
커밋
25be79c1a5
5개의 변경된 파일20개의 추가작업 그리고 136개의 파일을 삭제
  1. 0 1
      component.json
  2. 2 22
      src/compiler.js
  3. 0 20
      src/directives/component.js
  4. 17 1
      src/directives/index.js
  5. 1 92
      src/directives/with.js

+ 0 - 1
component.json

@@ -23,7 +23,6 @@
         "src/transition.js",
         "src/batcher.js",
         "src/directives/index.js",
-        "src/directives/component.js",
         "src/directives/if.js",
         "src/directives/repeat.js",
         "src/directives/on.js",

+ 2 - 22
src/compiler.js

@@ -339,13 +339,9 @@ CompilerProto.compile = function (node, root) {
         // special attributes to check
         var directive, repeatExp, viewExp, Component
 
-        // It is important that we access these attributes
-        // procedurally because the order matters.
-        // `utils.attr` removes the attribute once it gets the
-        // value, so we should not access them all at once.
+        // priority order for directives that create child VMs:
+        // repeat => view => component
 
-        // v-repeat has the highest priority
-        // and we need to preserve all other attributes for it.
         if (repeatExp = utils.attr(node, 'repeat')) {
 
             // repeat block cannot have v-id at the same time.
@@ -364,7 +360,6 @@ CompilerProto.compile = function (node, root) {
                 compiler.deferred.push(directive)
             }
 
-        // Child component has 2nd highest priority
         } else if (root !== true && (Component = this.resolveComponent(node, undefined, true))) {
 
             directive = Directive.parse('component', '', compiler, node)
@@ -373,23 +368,8 @@ CompilerProto.compile = function (node, root) {
                 compiler.deferred.push(directive)
             }
 
-            // should build component
-
-            // withExp = Directive.split(withExp || '')
-            // withExp.forEach(function (exp, i) {
-            //     var directive = Directive.parse('with', exp, compiler, node)
-            //     if (directive) {
-            //         // notify the directive that this is the
-            //         // last expression in the group
-            //         directive.last = i === withExp.length - 1
-            //         compiler.deferred.push(directive)
-            //     }
-            // })
-
         } else {
 
-            // remove the component directive
-            utils.attr(node, 'component')
             // compile normal directives
             compiler.compileNode(node)
 

+ 0 - 20
src/directives/component.js

@@ -1,20 +0,0 @@
-module.exports = {
-
-    isLiteral: true,
-
-    bind: function () {
-        if (!this.el.vue_vm) {
-            this.component = new this.Ctor({
-                el: this.el,
-                parent: this.vm
-            })
-        }
-    },
-
-    unbind: function () {
-        if (this.component) {
-            this.component.$destroy()
-        }
-    }
-
-}

+ 17 - 1
src/directives/index.js

@@ -13,7 +13,23 @@ module.exports = {
     style     : require('./style'),
     partial   : require('./partial'),
     view      : require('./view'),
-    component : require('./component'),
+
+    component : {
+        isLiteral: true,
+        bind: function () {
+            if (!this.el.vue_vm) {
+                this.component = new this.Ctor({
+                    el: this.el,
+                    parent: this.vm
+                })
+            }
+        },
+        unbind: function () {
+            if (this.component) {
+                this.component.$destroy()
+            }
+        }
+    },
 
     attr: {
         bind: function () {

+ 1 - 92
src/directives/with.js

@@ -44,95 +44,4 @@ module.exports = {
         }
     }
 
-}
-
-// var utils = require('../utils')
-
-// module.exports = {
-
-//     bind: function () {
-//         if (this.el.vue_vm) {
-//             this.subVM = this.el.vue_vm
-//             var compiler = this.subVM.$compiler
-//             if (this.arg && !compiler.bindings[this.arg]) {
-//                 compiler.createBinding(this.arg)
-//             }
-//         } else if (this.isEmpty) {
-//             this.build()
-//         }
-//     },
-
-//     update: function (value, init) {
-//         var vm = this.subVM,
-//             key = this.arg || '$data'
-//         if (!vm) {
-//             this.build(value)
-//         } else if (!this.lock && vm[key] !== value) {
-//             vm[key] = value
-//         }
-//         if (init) {
-//             // watch after first set
-//             this.watch()
-//             // The v-with directive can have multiple expressions,
-//             // and we want to make sure when the ready hook is called
-//             // on the subVM, all these clauses have been properly set up.
-//             // So this is a hack that sniffs whether we have reached
-//             // the last expression. We hold off the subVM's ready hook
-//             // until we are actually ready.
-//             if (this.last) {
-//                 this.subVM.$compiler.execHook('ready')
-//             }
-//         }
-//     },
-
-//     build: function (value) {
-//         var data = value
-//         if (this.arg) {
-//             data = {}
-//             data[this.arg] = value
-//         }
-//         var Ctor = this.compiler.resolveComponent(this.el, data)
-//         this.subVM = new Ctor({
-//             el     : this.el,
-//             data   : data,
-//             parent : this.vm,
-//             compilerOptions: {
-//                 // it is important to delay the ready hook
-//                 // so that when it's called, all `v-with` wathcers
-//                 // would have been set up.
-//                 delayReady: !this.last
-//             }
-//         })
-//         // mark that this VM is created by v-with
-//         utils.defProtected(this.subVM, '$with', true)
-//     },
-
-//     /**
-//      *  For inhertied keys, need to watch
-//      *  and sync back to the parent
-//      */
-//     watch: function () {
-//         if (!this.arg) return
-//         var self    = this,
-//             key     = self.key,
-//             ownerVM = self.binding.compiler.vm
-//         this.subVM.$compiler.observer.on('change:' + this.arg, function (val) {
-//             if (!self.lock) {
-//                 self.lock = true
-//                 utils.nextTick(function () {
-//                     self.lock = false
-//                 })
-//             }
-//             ownerVM.$set(key, val)
-//         })
-//     },
-
-//     unbind: function () {
-//         // all watchers are turned off during destroy
-//         // so no need to worry about it
-//         if (this.subVM.$with) {
-//             this.subVM.$destroy()
-//         }
-//     }
-
-// }
+}