0.0.104 • Published 3 years ago

@anic/proxy v0.0.104

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@anic/proxy

proxy for JavaScript

Install

$ yarn add @anic/proxy

Usage

import proxy from '@anic/proxy';

let obj1 = { key1: 1 },
    obj2 = { key1: 0, key2() { return this.key1; } },
    obj = proxy(obj1, obj2, 1);

// 校验结果
expect(obj).toHaveProperty('key1', 1);
expect(obj).toHaveProperty('key2');
expect(obj.key2()).toBe(1);

// 更新属性
obj.key1 = 2;
obj.key2 = () => 3;

// 校验结果
expect(obj.key1).toBe(2);
expect(obj.key2()).toBe(3);
expect(obj1.key1).toBe(obj.key1);
expect(obj2.key1).toBe(0);
expect(obj2.key2).toBe(obj.key2);

// 更新被代理对象
obj1.key1 = { value: 2 };
obj2.key2 = function () { return this.key1.value ++; };

// 校验结果
expect(obj.key1).toEqual({ value: 2 });
expect(obj.key2()).toBe(2);
expect(obj.key1).toEqual({ value: 3 });
0.0.104

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago