fix(reactivity): ensure that shallow and normal proxies are tracked seperately (close #2843) (#2851)

fix #2843
This commit is contained in:
Thorsten Lünborg
2021-03-26 20:39:56 +01:00
committed by GitHub
parent 68de9f408a
commit 22cc4a7659
4 changed files with 47 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import { shallowReactive, isReactive, reactive } from '../src/reactive'
import { isReactive, reactive, shallowReactive } from '../src/reactive'
import { effect } from '../src/effect'
describe('shallowReactive', () => {
@@ -13,6 +14,16 @@ describe('shallowReactive', () => {
expect(isReactive(props.n)).toBe(true)
})
// #2843
test('should allow shallow und normal reactive for same target', async () => {
const original = { foo: {} }
const shallowProxy = shallowReactive(original)
const reactiveProxy = reactive(original)
expect(shallowProxy).not.toBe(reactiveProxy)
expect(isReactive(shallowProxy.foo)).toBe(false)
expect(isReactive(reactiveProxy.foo)).toBe(true)
})
describe('collections', () => {
test('should be reactive', () => {
const shallowSet = shallowReactive(new Set())

View File

@@ -1,4 +1,4 @@
import { isReactive, isReadonly, shallowReadonly } from '../src'
import { isReactive, isReadonly, readonly, shallowReadonly } from '../src'
describe('reactivity/shallowReadonly', () => {
test('should not make non-reactive properties reactive', () => {
@@ -27,6 +27,16 @@ describe('reactivity/shallowReadonly', () => {
).not.toHaveBeenWarned()
})
// #2843
test('should differentiate from normal readonly calls', async () => {
const original = { foo: {} }
const shallowProxy = shallowReadonly(original)
const reactiveProxy = readonly(original)
expect(shallowProxy).not.toBe(reactiveProxy)
expect(isReadonly(shallowProxy.foo)).toBe(false)
expect(isReadonly(reactiveProxy.foo)).toBe(true)
})
describe('collection/Map', () => {
;[Map, WeakMap].forEach(Collection => {
test('should make the map/weak-map readonly', () => {