Immutable for Typescript
yarn add @sudoo/immutable
# Or
npm install @sudoo/immutable --save
Clone function is supported by @sudoo/duplicated
package.
import { clone } from "@sudoo/immutable";
const newObject = clone(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
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
For more advanced way to use this package, see Immutable Medium document.