Skip to content

Commit d69d3bf

Browse files
committed
fix(reactivity): revert to Reflect.get and add test cases
1 parent 068902a commit d69d3bf

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/reactivity/__tests__/effect.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ describe('reactivity/effect', () => {
249249
expect(dummy).toBe(newFunc)
250250
})
251251

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+
252282
it('should not observe set operations without a value change', () => {
253283
let hasDummy, getDummy
254284
const obj = reactive({ prop: 'value' })

packages/reactivity/src/baseHandlers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ const builtInSymbols = new Set(
1212
)
1313

1414
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)
1817
if (isSymbol(key) && builtInSymbols.has(key)) {
1918
return res
2019
}

0 commit comments

Comments
 (0)