@zalelion/immutable-object
v0.0.6
Published
## Install
Downloads
1
Readme
immutable-object
Install
yarn add @zalelion/immutable-object
Example
import { sync } from "../src/index";
const obj = {
name: "hello",
change(name) {
this.name = name;
},
set: new Set,
map: new Map,
sub: { arr: ["1", "2", "333", "44444", "555555"] }
}
const [proxy, unlisten] = sync<typeof obj>(obj, newobj => console.log(newobj));
proxy.map.set("a", "2");
Output:
{ ...
map: Map { 'a' => '2' }
}
And:
proxy.change("lion");
Output:
{ name: 'lion',
...
}
API
import { sync } from "../src/index";
const [obj_proxy , unsubscribe] = sync(obj, cb);
obj
is a object.cb(newImmutableObj)
when obj changed , then callback return a immutable object.obj_proxy
is a Proxy , call it tocb(newImmutableObj)
unsubscribe
is a function, stop subscribe obj change event.