目标

判断是否由 reactive 或 readonly 创建的响应性对象
即结合 isReactive 和 isReadonly 判断即可

  1. it('reactive', () => {
  2. const original = { foo: 1 };
  3. const observed = reactive(original);
  4. expect(isProxy(observed)).toBe(true);
  5. });
  6. it('happy path', () => {
  7. const original = { foo: 1, bar: { baz: 2 } };
  8. const wrapped = readonly(original);
  9. expect(isProxy(wrapped)).toBe(true);
  10. });

实现

  1. export function isProxy(value) {
  2. return isReactive(value) || isReadonly(value);
  3. }