binding should only have access to compiler

This commit is contained in:
Evan You 2013-08-14 19:31:17 -04:00
parent a85453cc89
commit f071f87bc7
4 changed files with 10 additions and 11 deletions

View File

@ -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
}
/*

View File

@ -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
}
/*

View File

@ -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)
},

View File

@ -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)