Skip to content

Commit

Permalink
fix: don't invoke Vue getters in settter
Browse files Browse the repository at this point in the history
Fixes vuejs#498
  • Loading branch information
chearon committed Aug 13, 2021
1 parent 1b63186 commit a310d3c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/reactivity/reactive.ts
Expand Up @@ -80,12 +80,14 @@ export function defineAccessControl(target: AnyObject, key: any, val?: any) {
}
}

let valIsRef = isRef(val)

setupAccessControl(val)
proxy(target, key, {
get: function getterHandler() {
const value = getter ? getter.call(target) : val
// if the key is equal to RefKey, skip the unwrap logic
if (key !== RefKey && isRef(value)) {
if (key !== RefKey && valIsRef) {
return value.value
} else {
return value
Expand All @@ -94,16 +96,17 @@ export function defineAccessControl(target: AnyObject, key: any, val?: any) {
set: function setterHandler(newVal: any) {
if (getter && !setter) return

const value = getter ? getter.call(target) : val
// If the key is equal to RefKey, skip the unwrap logic
// If and only if "value" is ref and "newVal" is not a ref,
// the assignment should be proxied to "value" ref.
if (key !== RefKey && isRef(value) && !isRef(newVal)) {
value.value = newVal
if (key !== RefKey && valIsRef && !isRef(newVal)) {
val.value = newVal
} else if (setter) {
setter.call(target, newVal)
valIsRef = isRef(newVal)
} else {
val = newVal
valIsRef = isRef(newVal)
}
setupAccessControl(newVal)
},
Expand Down

0 comments on commit a310d3c

Please sign in to comment.