fix(reactivity): use isExtensible instead of isFrozen (#1753)

close #1784
This commit is contained in:
wujieZ 2020-08-05 23:53:50 +08:00 committed by GitHub
parent 3692f2738f
commit 2787c34cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -183,11 +183,16 @@ describe('reactivity/reactive', () => {
expect(isReactive(obj.bar)).toBe(false)
})
test('should not observe frozen objects', () => {
test('should not observe non-extensible objects', () => {
const obj = reactive({
foo: Object.freeze({ a: 1 })
foo: Object.preventExtensions({ a: 1 }),
// sealed or frozen objects are considered non-extensible as well
bar: Object.freeze({ a: 1 }),
baz: Object.seal({ a: 1 })
})
expect(isReactive(obj.foo)).toBe(false)
expect(isReactive(obj.bar)).toBe(false)
expect(isReactive(obj.baz)).toBe(false)
})
test('should not observe objects with __v_skip', () => {

View File

@ -39,7 +39,7 @@ const canObserve = (value: Target): boolean => {
return (
!value[ReactiveFlags.SKIP] &&
isObservableType(toRawType(value)) &&
!Object.isFrozen(value)
Object.isExtensible(value)
)
}