Skip to content

Commit 6980f59

Browse files
committed
tweak compiler
1 parent 68f7ec7 commit 6980f59

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/compiler.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,28 @@ function Compiler (vm, options) {
114114
}
115115
}
116116

117+
// copy data properties to vm
118+
// so user can access them in the created hook
119+
extend(vm, data)
120+
vm.$data = data
121+
117122
// beforeCompile hook
118123
compiler.execHook('created')
119124

120125
// the user might have set some props on the vm
121126
// so copy it back to the data...
127+
var vmProp
122128
for (key in vm) {
123-
if (key.charAt(0) !== '$' && typeof vm[key] !== 'function') {
124-
data[key] = vm[key]
129+
vmProp = vm[key]
130+
if (
131+
key.charAt(0) !== '$' &&
132+
typeof vmProp !== 'function' &&
133+
data[key] !== vmProp
134+
) {
135+
data[key] = vmProp
125136
}
126137
}
127138

128-
// copy meta properties
129-
vm.$index = data.$index
130-
vm.$value = data.$value
131-
vm.$key = data.$key
132-
133139
// observe the data
134140
compiler.observeData(data)
135141

@@ -621,7 +627,6 @@ CompilerProto.createBinding = function (key, directive) {
621627
* and observe the initial value
622628
*/
623629
CompilerProto.defineProp = function (key, binding) {
624-
625630
var compiler = this,
626631
data = compiler.data,
627632
ob = data.__emitter__
@@ -656,21 +661,16 @@ CompilerProto.defineProp = function (key, binding) {
656661
* not in the data.
657662
*/
658663
CompilerProto.defineMeta = function (key, binding) {
659-
var vm = this.vm,
660-
ob = this.observer,
661-
value = binding.value = this.data[key]
662-
// remove initital meta in data, since the same piece
663-
// of data can be observed by different VMs, each have
664-
// its own associated meta info.
664+
var ob = this.observer
665+
binding.value = this.data[key]
665666
delete this.data[key]
666-
Object.defineProperty(vm, key, {
667+
Object.defineProperty(this.vm, key, {
667668
get: function () {
668669
if (Observer.shouldGet) ob.emit('get', key)
669-
return value
670+
return binding.value
670671
},
671672
set: function (val) {
672673
ob.emit('set', key, val)
673-
value = val
674674
}
675675
})
676676
}

0 commit comments

Comments
 (0)