File tree 2 files changed +32
-3
lines changed
2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,36 @@ describe('reactivity/effect', () => {
249
249
expect ( dummy ) . toBe ( newFunc )
250
250
} )
251
251
252
+ it ( 'should observe chained getters relying on this' , ( ) => {
253
+ const obj = reactive ( {
254
+ a : 1 ,
255
+ get b ( ) {
256
+ return this . a
257
+ }
258
+ } )
259
+
260
+ let dummy
261
+ effect ( ( ) => ( dummy = obj . b ) )
262
+ expect ( dummy ) . toBe ( 1 )
263
+ obj . a ++
264
+ expect ( dummy ) . toBe ( 2 )
265
+ } )
266
+
267
+ it ( 'should observe methods relying on this' , ( ) => {
268
+ const obj = reactive ( {
269
+ a : 1 ,
270
+ b ( ) {
271
+ return this . a
272
+ }
273
+ } )
274
+
275
+ let dummy
276
+ effect ( ( ) => ( dummy = obj . b ( ) ) )
277
+ expect ( dummy ) . toBe ( 1 )
278
+ obj . a ++
279
+ expect ( dummy ) . toBe ( 2 )
280
+ } )
281
+
252
282
it ( 'should not observe set operations without a value change' , ( ) => {
253
283
let hasDummy , getDummy
254
284
const obj = reactive ( { prop : 'value' } )
Original file line number Diff line number Diff line change @@ -12,9 +12,8 @@ const builtInSymbols = new Set(
12
12
)
13
13
14
14
function createGetter ( isReadonly : boolean ) {
15
- return function get ( target : any , key : string | symbol ) {
16
- // not using Reflect.get here for perf reasons
17
- const res = target [ key ]
15
+ return function get ( target : any , key : string | symbol , receiver : any ) {
16
+ const res = Reflect . get ( target , key , receiver )
18
17
if ( isSymbol ( key ) && builtInSymbols . has ( key ) ) {
19
18
return res
20
19
}
You can’t perform that action at this time.
0 commit comments