Sudoo-Immutable

Build Status codecov npm version downloads

:closed_lock_with_key: Immutable for Typescript

Install

yarn add @sudoo/immutable
# Or
npm install @sudoo/immutable --save

Clone Object

Clone function is supported by @sudoo/duplicated package.

import { clone } from "@sudoo/immutable";

const newObject = clone(object);

Produce Object

Within produce function, you can edit object immutably within mutable method.

import { produce } from "@sudoo/immutable";

const newObject = produce(oldObject, (draft) => {
    object.hello = "world";
});
oldObject // Not Edited
newObject // Edited

Async Produce Object

Within produce function, you can edit object immutably within mutable method.

import { produce } from "@sudoo/immutable";

const newObject = await asyncProduce(oldObject, async (draft) => {
    object.hello = await getWorld();
});
oldObject // Not Edited
newObject // Edited

Advanced

For more advanced way to use this package, see Immutable Medium document.