This package has been deprecated

Author message:

Renamed to constant-ts

constant.ts

1.1.0 • Public • Published

Constant

build status

A class that represents immutable data.

Constant<T> objects contain inner copy of original model of class T and provide read-only access to fields.

Usage

For class

class TreeNode
{
    parent: TreeNode;
    value: string;
}

Lets create some data structure:

let root = new TreeNode();
root.value = "root";

let child = new TreeNode();
child.parent = root;
child.value = "child";

Probably it should be stored in some immutable store (like Redux one 😉).

To provide new state with a garant of lack of mutation on original model we use Constant<TreeNode>:

let childConstant = new Constant(child);
...

console.log(childConstant); // is Constant<TreeNode> for child

let childValue = childConstant.get(c => c.value);
console.log(childValue); // "child"

let rootConstant = childConstant.get(c => c.root);
let rootValue = rootConstant.get(c => c.value);
console.log(rootValue); // "root"

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i constant.ts

    Weekly Downloads

    3

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • sakhatskiy