0.1.2 • Published 3 years ago
reactive-proxy v0.1.2
Reactive Proxy Implementation (ES6+)
Example
import ReactiveProxy from 'reactive-proxy';
const source = {a: { b: { c: { d: 5 } } } };
const proxy = new ReactiveProxy(source, {
get(target, prop, receiver, propPath) {
console.log("get prop:", propPath);
return Reflect.get(target, prop, receiver);
},
set(target, p, value, r, propPath, reactiveWrapper) {
console.log("set prop:", propPath);
return Reflect.set(
target,
p,
reactiveWrapper(value), // Wrap to Reactive Proxy Object
r
);
}
});
let a = proxy.a.b.c.d;
// Console Output: get prop: ["a", "b", "c", "d"]
proxy.b = {};
// Console Output: set prop: ["b"]
console.log(proxy.b) // ReactiveChild {}
proxy.b.b
// Console Output: get prop: ["b", "b"]