实现 isProxy

isProxy检查一个对象是不是通过 reactive 或者 readonly 创建的响应式对象,实际上就是 isReactiveisReadonly 的结合体

实现 isProxy 功能

单测

1
2
3
4
5
6
7
8
9
10
11
//reactivity/__test__/reactive.spec.ts
...
import { isProxy, reactive, readonly } from '../reactive'
it('isProxy', () => {
const user = { age: 18, name: '秋簌' }
const reactiveObj = reactive(user)
const readonlyObj = readonly(user)
expect(isProxy(reactiveObj)).toBe(true)
expect(isProxy(readonlyObj)).toBe(true)
expect(isProxy(user)).toBe(false)
})

实现单测

1
2
3
//reactivity/reactive.ts
...
export const isProxy = raw => isReactive(raw) || isReadonly(raw)