Przeglądaj źródła

binding should only have access to compiler

Evan You 13 lat temu
rodzic
commit
f071f87bc7
4 zmienionych plików z 10 dodań i 11 usunięć
  1. 3 5
      src/binding.js
  2. 1 1
      src/directive-parser.js
  3. 2 2
      src/directives/index.js
  4. 4 3
      src/directives/on.js

+ 3 - 5
src/binding.js

@@ -11,7 +11,6 @@ var utils    = require('./utils'),
  */
 function Binding (compiler, key) {
     this.compiler = compiler
-    this.vm = compiler.vm
     this.key = key
     var path = key.split('.')
     this.inspect(utils.getNestedValue(compiler.vm, path))
@@ -35,8 +34,8 @@ BindingProto.inspect = function (value) {
             if (l === 1 || (l === 2 && value.set)) {
                 this.isComputed = true // computed property
                 this.rawGet = value.get
-                value.get = value.get.bind(this.vm)
-                if (value.set) value.set = value.set.bind(this.vm)
+                value.get = value.get.bind(this.compiler.vm)
+                if (value.set) value.set = value.set.bind(this.compiler.vm)
             }
         }
     } else if (type === 'Array') {
@@ -144,8 +143,7 @@ BindingProto.unbind = function () {
         subs.splice(subs.indexOf(this), 1)
     }
     if (Array.isArray(this.value)) this.value.off('mutate')
-    this.vm = this.compiler = this.pubs =
-    this.subs = this.instances = this.deps = null
+    this.compiler = this.pubs = this.subs = this.instances = this.deps = null
 }
 
 /*

+ 1 - 1
src/directive-parser.js

@@ -145,7 +145,7 @@ DirProto.parseKey = function (rawKey) {
 DirProto.unbind = function (update) {
     if (!this.el) return
     if (this._unbind) this._unbind(update)
-    if (!update) this.vm = this.el = this.compiler = this.binding =  null
+    if (!update) this.vm = this.el = this.binding = this.compiler = null
 }
 
 /*

+ 2 - 2
src/directives/index.js

@@ -51,7 +51,7 @@ module.exports = {
             if (this.oneway) return
             var el = this.el, self = this
             this.change = function () {
-                self.compiler.vm[self.key] = el.value
+                self.vm[self.key] = el.value
             }
             el.addEventListener('keyup', this.change)
         },
@@ -69,7 +69,7 @@ module.exports = {
             if (this.oneway) return
             var el = this.el, self = this
             this.change = function () {
-                self.compiler.vm[self.key] = el.checked
+                self.vm[self.key] = el.checked
             }
             el.addEventListener('change', this.change)
         },

+ 4 - 3
src/directives/on.js

@@ -29,7 +29,7 @@ module.exports = {
 
         var compiler = this.compiler,
             event    = this.arg,
-            ownerVM  = this.binding.vm
+            ownerVM  = this.binding.compiler.vm
 
         if (compiler.each && event !== 'blur' && event !== 'blur') {
 
@@ -56,10 +56,11 @@ module.exports = {
         } else {
 
             // a normal, single element handler
+            var vm = this.vm
             this.handler = function (e) {
                 e.el = e.currentTarget
-                e.vm = compiler.vm
-                handler.call(compiler.vm, e)
+                e.vm = vm
+                handler.call(vm, e)
             }
             this.el.addEventListener(event, this.handler)