Skip to content

Commit

Permalink
fix(reactivity): check own property for existing proxy of target
Browse files Browse the repository at this point in the history
fix #1107
  • Loading branch information
yyx990803 committed May 3, 2020
1 parent 8bab78b commit 6be2b73
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject, toRawType, def } from '@vue/shared'
import { isObject, toRawType, def, hasOwn } from '@vue/shared'
import {
mutableHandlers,
readonlyHandlers,
Expand Down Expand Up @@ -116,18 +116,19 @@ function createReactiveObject(
return target
}
// target already has corresponding Proxy
let observed = isReadonly ? target.__v_readonly : target.__v_reactive
if (observed !== void 0) {
return observed
if (
hasOwn(target, isReadonly ? ReactiveFlags.readonly : ReactiveFlags.reactive)
) {
return isReadonly ? target.__v_readonly : target.__v_reactive
}
// only a whitelist of value types can be observed.
if (!canObserve(target)) {
return target
}
const handlers = collectionTypes.has(target.constructor)
? collectionHandlers
: baseHandlers
observed = new Proxy(target, handlers)
const observed = new Proxy(
target,
collectionTypes.has(target.constructor) ? collectionHandlers : baseHandlers
)
def(
target,
isReadonly ? ReactiveFlags.readonly : ReactiveFlags.reactive,
Expand Down

0 comments on commit 6be2b73

Please sign in to comment.