File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ describe('api: options', () => {
113
113
const spyB = jest . fn ( returnThis )
114
114
const spyC = jest . fn ( returnThis )
115
115
const spyD = jest . fn ( returnThis )
116
+ const spyE = jest . fn ( returnThis )
116
117
117
118
let ctx : any
118
119
const Comp = {
@@ -123,7 +124,10 @@ describe('api: options', () => {
123
124
baz : {
124
125
qux : 3
125
126
} ,
126
- qux : 4
127
+ qux : 4 ,
128
+ dot : {
129
+ path : 5
130
+ }
127
131
}
128
132
} ,
129
133
watch : {
@@ -137,7 +141,8 @@ describe('api: options', () => {
137
141
} ,
138
142
qux : {
139
143
handler : 'onQuxChange'
140
- }
144
+ } ,
145
+ 'dot.path' : spyE
141
146
} ,
142
147
methods : {
143
148
onFooChange : spyA ,
@@ -175,6 +180,11 @@ describe('api: options', () => {
175
180
await nextTick ( )
176
181
expect ( spyD ) . toHaveBeenCalledTimes ( 1 )
177
182
assertCall ( spyD , 0 , [ 5 , 4 ] )
183
+
184
+ ctx . dot . path ++
185
+ await nextTick ( )
186
+ expect ( spyE ) . toHaveBeenCalledTimes ( 1 )
187
+ assertCall ( spyE , 0 , [ 6 , 5 ] )
178
188
} )
179
189
180
190
test ( 'watch array' , async ( ) => {
Original file line number Diff line number Diff line change @@ -816,7 +816,9 @@ function createWatcher(
816
816
publicThis : ComponentPublicInstance ,
817
817
key : string
818
818
) {
819
- const getter = ( ) => ( publicThis as any ) [ key ]
819
+ const getter = key . includes ( '.' )
820
+ ? createPathGetter ( publicThis , key )
821
+ : ( ) => ( publicThis as any ) [ key ]
820
822
if ( isString ( raw ) ) {
821
823
const handler = ctx [ raw ]
822
824
if ( isFunction ( handler ) ) {
@@ -840,7 +842,18 @@ function createWatcher(
840
842
}
841
843
}
842
844
} else if ( __DEV__ ) {
843
- warn ( `Invalid watch option: "${ key } "` )
845
+ warn ( `Invalid watch option: "${ key } "` , raw )
846
+ }
847
+ }
848
+
849
+ function createPathGetter ( ctx : any , path : string ) {
850
+ const segments = path . split ( '.' )
851
+ return ( ) => {
852
+ let cur = ctx
853
+ for ( let i = 0 ; i < segments . length && cur ; i ++ ) {
854
+ cur = cur [ segments [ i ] ]
855
+ }
856
+ return cur
844
857
}
845
858
}
846
859
You can’t perform that action at this time.
0 commit comments