0.0.6 • Published 6 years ago
@zalelion/immutable-object v0.0.6
immutable-object
Install
yarn add @zalelion/immutable-objectExample
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);objis a object.cb(newImmutableObj)when obj changed , then callback return a immutable object.obj_proxyis a Proxy , call it tocb(newImmutableObj)unsubscribeis a function, stop subscribe obj change event.