@@ -13,7 +13,6 @@ var Emitter = require('./emitter'),
13
13
slice = [ ] . slice ,
14
14
makeHash = utils . hash ,
15
15
extend = utils . extend ,
16
- def = utils . defProtected ,
17
16
hasOwn = ( { } ) . hasOwnProperty ,
18
17
19
18
// hooks to register
@@ -59,33 +58,32 @@ function Compiler (vm, options) {
59
58
utils . log ( '\nnew VM instance: ' + el . tagName + '\n' )
60
59
61
60
// set compiler properties
62
- compiler . vm = el . vue_vm = vm
63
- compiler . bindings = makeHash ( )
64
- compiler . expCache = compiler . expCache || makeHash ( )
65
- compiler . dirs = [ ]
66
- compiler . deferred = [ ]
67
- compiler . computed = [ ]
68
- compiler . children = [ ]
69
- compiler . emitter = new Emitter ( )
61
+ compiler . vm = el . vue_vm = vm
62
+ compiler . bindings = makeHash ( )
63
+ compiler . expCache = compiler . expCache || makeHash ( )
64
+ compiler . dirs = [ ]
65
+ compiler . deferred = [ ]
66
+ compiler . computed = [ ]
67
+ compiler . children = [ ]
68
+ compiler . emitter = new Emitter ( )
70
69
compiler . emitter . _ctx = vm
71
- compiler . delegators = makeHash ( )
70
+ compiler . delegators = makeHash ( )
72
71
73
- // set inenumerable VM properties
74
- def ( vm , '$' , makeHash ( ) )
75
- def ( vm , ' $el' , el )
76
- def ( vm , ' $options' , options )
77
- def ( vm , ' $compiler' , compiler )
78
- def ( vm , ' $event' , null , false , true )
72
+ // set VM properties
73
+ vm . $ = makeHash ( )
74
+ vm . $el = el
75
+ vm . $options = options
76
+ vm . $compiler = compiler
77
+ vm . $event = null
79
78
80
- // set parent
79
+ // set parent & root
81
80
var parentVM = options . parent
82
81
if ( parentVM ) {
83
82
compiler . parent = parentVM . $compiler
84
83
parentVM . $compiler . children . push ( compiler )
85
- def ( vm , ' $parent' , parentVM )
84
+ vm . $parent = parentVM
86
85
}
87
- // set root
88
- def ( vm , '$root' , getRoot ( compiler ) . vm )
86
+ vm . $root = getRoot ( compiler ) . vm
89
87
90
88
// setup observer
91
89
compiler . setupObserver ( )
@@ -122,26 +120,18 @@ function Compiler (vm, options) {
122
120
// the user might have set some props on the vm
123
121
// so copy it back to the data...
124
122
for ( key in vm ) {
125
- if ( typeof vm [ key ] !== 'function' ) {
123
+ if ( key . charAt ( 0 ) !== '$' && typeof vm [ key ] !== 'function' ) {
126
124
data [ key ] = vm [ key ]
127
125
}
128
126
}
129
127
128
+ // copy meta properties
130
129
vm . $index = data . $index
131
130
vm . $value = data . $value
132
131
vm . $key = data . $key
133
132
134
133
// observe the data
135
134
compiler . observeData ( data )
136
-
137
- // for repeated items, create index/key bindings
138
- // because they are ienumerable
139
- if ( compiler . repeat ) {
140
- compiler . createBinding ( '$index' )
141
- if ( data . $key ) {
142
- compiler . createBinding ( '$key' )
143
- }
144
- }
145
135
146
136
// now parse the DOM, during which we will create necessary bindings
147
137
// and bind the parsed directives
@@ -668,7 +658,7 @@ CompilerProto.defineProp = function (key, binding) {
668
658
CompilerProto . defineMeta = function ( key , binding ) {
669
659
var vm = this . vm ,
670
660
ob = this . observer ,
671
- value = binding . value = vm [ key ]
661
+ value = binding . value = this . data [ key ]
672
662
// remove initital meta in data, since the same piece
673
663
// of data can be observed by different VMs, each have
674
664
// its own associated meta info.
0 commit comments