@zalelion/immutable-object
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

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 to cb(newImmutableObj)
  • unsubscribe is a function, stop subscribe obj change event.

Readme

Keywords

none

Package Sidebar

Install

npm i @zalelion/immutable-object

Weekly Downloads

1

Version

0.0.6

License

ISC

Unpacked Size

47.6 kB

Total Files

9

Last publish

Collaborators

  • leozale