1.2.0 • Published 3 years ago
@nano-utils/object-proxy v1.2.0
Description
A small library to make object proxying easier
Installation
npm i @nano-utils/object-proxyor
yarn add @nano-utils/object-proxyUsage
The makeProxy function creates a proxy object, which will call the supplied listener upon property changes with the property's path (delimited by .), the new value of the property, and the old value of the property
import { makeProxy } from '@nano-utils/object-proxy';
const obj = { foo: 'bar' };
const proxy = makeProxy(obj, (prop, newValue, oldValue) => console.log(prop, newValue, oldValue));
proxy.foo = 'baz'; // foo baz barThis package comes fully typed:
import { makeProxy } from '@nano-utils/object-proxy';
type MyObject = {
foo: string;
};
const obj: MyObject = { foo: 'bar' };
const proxy = makeProxy<MyObject>(obj, (prop, newValue, oldValue) => console.log(prop, newValue, oldValue));
proxy.foo = 'baz'; // foo baz bar