fix(reactivity): revert to Reflect.get and add test cases
This commit is contained in:
parent
068902abec
commit
d69d3bf765
@ -249,6 +249,36 @@ describe('reactivity/effect', () => {
|
|||||||
expect(dummy).toBe(newFunc)
|
expect(dummy).toBe(newFunc)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should observe chained getters relying on this', () => {
|
||||||
|
const obj = reactive({
|
||||||
|
a: 1,
|
||||||
|
get b() {
|
||||||
|
return this.a
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let dummy
|
||||||
|
effect(() => (dummy = obj.b))
|
||||||
|
expect(dummy).toBe(1)
|
||||||
|
obj.a++
|
||||||
|
expect(dummy).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should observe methods relying on this', () => {
|
||||||
|
const obj = reactive({
|
||||||
|
a: 1,
|
||||||
|
b() {
|
||||||
|
return this.a
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let dummy
|
||||||
|
effect(() => (dummy = obj.b()))
|
||||||
|
expect(dummy).toBe(1)
|
||||||
|
obj.a++
|
||||||
|
expect(dummy).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
it('should not observe set operations without a value change', () => {
|
it('should not observe set operations without a value change', () => {
|
||||||
let hasDummy, getDummy
|
let hasDummy, getDummy
|
||||||
const obj = reactive({ prop: 'value' })
|
const obj = reactive({ prop: 'value' })
|
||||||
|
@ -12,9 +12,8 @@ const builtInSymbols = new Set(
|
|||||||
)
|
)
|
||||||
|
|
||||||
function createGetter(isReadonly: boolean) {
|
function createGetter(isReadonly: boolean) {
|
||||||
return function get(target: any, key: string | symbol) {
|
return function get(target: any, key: string | symbol, receiver: any) {
|
||||||
// not using Reflect.get here for perf reasons
|
const res = Reflect.get(target, key, receiver)
|
||||||
const res = target[key]
|
|
||||||
if (isSymbol(key) && builtInSymbols.has(key)) {
|
if (isSymbol(key) && builtInSymbols.has(key)) {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user