feat(reactivity): add isShallow api

This commit is contained in:
Evan You
2022-01-18 09:17:22 +08:00
parent 0c06c748a5
commit 9fda9411ec
9 changed files with 39 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ import {
} from '../src/index'
import { computed } from '@vue/runtime-dom'
import { shallowRef, unref, customRef, triggerRef } from '../src/ref'
import { isShallow } from '../src/reactive'
describe('reactivity/ref', () => {
it('should hold a value', () => {
@@ -227,6 +228,10 @@ describe('reactivity/ref', () => {
expect(dummy).toBe(2)
})
test('shallowRef isShallow', () => {
expect(isShallow(shallowRef({ a: 1 }))).toBe(true)
})
test('isRef', () => {
expect(isRef(ref(1))).toBe(true)
expect(isRef(computed(() => 1))).toBe(true)

View File

@@ -1,4 +1,10 @@
import { isReactive, reactive, shallowReactive } from '../src/reactive'
import {
isReactive,
isShallow,
reactive,
shallowReactive,
shallowReadonly
} from '../src/reactive'
import { effect } from '../src/effect'
@@ -24,6 +30,11 @@ describe('shallowReactive', () => {
expect(isReactive(reactiveProxy.foo)).toBe(true)
})
test('isShallow', () => {
expect(isShallow(shallowReactive({}))).toBe(true)
expect(isShallow(shallowReadonly({}))).toBe(true)
})
describe('collections', () => {
test('should be reactive', () => {
const shallowSet = shallowReactive(new Set())