feat(reactivity): add shallowReactive function (#689)
This commit is contained in:
committed by
GitHub
parent
2d56dfdc4f
commit
7f38c1e0ff
@@ -1,5 +1,11 @@
|
||||
import { ref, isRef } from '../src/ref'
|
||||
import { reactive, isReactive, toRaw, markNonReactive } from '../src/reactive'
|
||||
import {
|
||||
reactive,
|
||||
isReactive,
|
||||
toRaw,
|
||||
markNonReactive,
|
||||
shallowReactive
|
||||
} from '../src/reactive'
|
||||
import { mockWarn } from '@vue/shared'
|
||||
import { computed } from '../src/computed'
|
||||
|
||||
@@ -212,4 +218,17 @@ describe('reactivity/reactive', () => {
|
||||
expect(isReactive(obj.foo)).toBe(true)
|
||||
expect(isReactive(obj.bar)).toBe(false)
|
||||
})
|
||||
|
||||
describe('shallowReactive', () => {
|
||||
test('should not make non-reactive properties reactive', () => {
|
||||
const props = shallowReactive({ n: { foo: 1 } })
|
||||
expect(isReactive(props.n)).toBe(false)
|
||||
})
|
||||
|
||||
test('should keep reactive properties reactive', () => {
|
||||
const props: any = shallowReactive({ n: reactive({ foo: 1 }) })
|
||||
props.n = reactive({ foo: 2 })
|
||||
expect(isReactive(props.n)).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user