@@ -68,20 +68,6 @@ function Compiler (vm, options) {
68
68
compiler . children = [ ]
69
69
compiler . emitter = new Emitter ( vm )
70
70
71
- // create bindings for computed properties
72
- if ( options . methods ) {
73
- for ( key in options . methods ) {
74
- compiler . createBinding ( key )
75
- }
76
- }
77
-
78
- // create bindings for methods
79
- if ( options . computed ) {
80
- for ( key in options . computed ) {
81
- compiler . createBinding ( key )
82
- }
83
- }
84
-
85
71
// VM ---------------------------------------------------------------------
86
72
87
73
// set VM properties
@@ -110,6 +96,20 @@ function Compiler (vm, options) {
110
96
// this is necesarry for all hooks and data observation events
111
97
compiler . setupObserver ( )
112
98
99
+ // create bindings for computed properties
100
+ if ( options . methods ) {
101
+ for ( key in options . methods ) {
102
+ compiler . createBinding ( key )
103
+ }
104
+ }
105
+
106
+ // create bindings for methods
107
+ if ( options . computed ) {
108
+ for ( key in options . computed ) {
109
+ compiler . createBinding ( key )
110
+ }
111
+ }
112
+
113
113
// initialize data
114
114
var data = compiler . data = options . data || { } ,
115
115
defaultData = options . defaultData
@@ -719,7 +719,7 @@ CompilerProto.createBinding = function (key, directive) {
719
719
compiler . defineExp ( key , binding , directive )
720
720
} else if ( isFn ) {
721
721
bindings [ key ] = binding
722
- binding . value = compiler . vm [ key ] = methods [ key ]
722
+ compiler . defineVmProp ( key , binding , methods [ key ] )
723
723
} else {
724
724
bindings [ key ] = binding
725
725
if ( binding . root ) {
@@ -729,9 +729,12 @@ CompilerProto.createBinding = function (key, directive) {
729
729
compiler . defineComputed ( key , binding , computed [ key ] )
730
730
} else if ( key . charAt ( 0 ) !== '$' ) {
731
731
// normal property
732
- compiler . defineProp ( key , binding )
732
+ compiler . defineDataProp ( key , binding )
733
733
} else {
734
- compiler . defineMeta ( key , binding )
734
+ // properties that start with $ are meta properties
735
+ // they should be kept on the vm but not in the data object.
736
+ compiler . defineVmProp ( key , binding , compiler . data [ key ] )
737
+ delete compiler . data [ key ]
735
738
}
736
739
} else if ( computed && computed [ utils . baseKey ( key ) ] ) {
737
740
// nested path on computed property
@@ -753,10 +756,10 @@ CompilerProto.createBinding = function (key, directive) {
753
756
}
754
757
755
758
/**
756
- * Define the getter/setter for a root-level property on the VM
757
- * and observe the initial value
759
+ * Define the getter/setter to proxy a root-level
760
+ * data property on the VM
758
761
*/
759
- CompilerProto . defineProp = function ( key , binding ) {
762
+ CompilerProto . defineDataProp = function ( key , binding ) {
760
763
var compiler = this ,
761
764
data = compiler . data ,
762
765
ob = data . __emitter__
@@ -786,14 +789,13 @@ CompilerProto.defineProp = function (key, binding) {
786
789
}
787
790
788
791
/**
789
- * Define a meta property, e.g. $index or $key,
790
- * which is bindable but only accessible on the VM,
792
+ * Define a vm property, e.g. $index, $key, or mixin methods
793
+ * which are bindable but only accessible on the VM,
791
794
* not in the data.
792
795
*/
793
- CompilerProto . defineMeta = function ( key , binding ) {
796
+ CompilerProto . defineVmProp = function ( key , binding , value ) {
794
797
var ob = this . observer
795
- binding . value = this . data [ key ]
796
- delete this . data [ key ]
798
+ binding . value = value
797
799
def ( this . vm , key , {
798
800
get : function ( ) {
799
801
if ( Observer . shouldGet ) ob . emit ( 'get' , key )
0 commit comments