Skip to content

Commit

Permalink
fix(reactivity): use isExtensible instead of isFrozen (#1753)
Browse files Browse the repository at this point in the history
close #1784
  • Loading branch information
wujieZ authored Aug 5, 2020
1 parent 3692f27 commit 2787c34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/reactivity/__tests__/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const canObserve = (value: Target): boolean => {
return (
!value[ReactiveFlags.SKIP] &&
isObservableType(toRawType(value)) &&
!Object.isFrozen(value)
Object.isExtensible(value)
)
}

Expand Down

0 comments on commit 2787c34

Please sign in to comment.