Skip to content

Commit

Permalink
fix(shallowReactive): should track value if already reactive when set…
Browse files Browse the repository at this point in the history
… in shallowReactive
  • Loading branch information
yyx990803 committed Dec 6, 2023
1 parent d30f6fd commit 0ad8e8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/instance/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function initProps(vm: Component, propsOptions: Object) {
)
}
},
true
true /* shallow */
)
} else {
defineReactive(props, key, value, undefined, true)
defineReactive(props, key, value, undefined, true /* shallow */)
}
// static props are already proxied on the component's prototype
// during Vue.extend(). We only need to proxy props defined at
Expand Down
7 changes: 4 additions & 3 deletions src/core/observer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export function defineReactive(
val?: any,
customSetter?: Function | null,
shallow?: boolean,
mock?: boolean
mock?: boolean,
observeEvenIfShallow = false
) {
const dep = new Dep()

Expand All @@ -150,7 +151,7 @@ export function defineReactive(
val = obj[key]
}

let childOb = !shallow && observe(val, false, mock)
let childOb = shallow ? val && val.__ob__ : observe(val, false, mock)
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
Expand Down Expand Up @@ -194,7 +195,7 @@ export function defineReactive(
} else {
val = newVal
}
childOb = !shallow && observe(newVal, false, mock)
childOb = shallow ? newVal && newVal.__ob__ : observe(newVal, false, mock)
if (__DEV__) {
dep.notify({
type: TriggerOpTypes.SET,
Expand Down

0 comments on commit 0ad8e8d

Please sign in to comment.