Immut
A draft-based immutable data library based on Immer
View the docs
TypeScript Usage
import Immut, { nothing, produce } from "@rbxts/immut";
let oldState: Array<string> | undefined;
const newState = produce(oldState, (draft) => {
if (!draft) return [];
if (Immut.table.find(draft, "abc") !== undefined) return nothing;
if (Immut.table.find(draft, "abc") === 1) return nothing;
Immut.table.insert(draft, 1, "draft-safe");
Immut.table.remove(draft);
Immut.table.remove(draft, 1);
draft.pop();
Immut.table.sort(draft, (a, b) => a > b);
Immut.table.clear(draft);
Immut.table.concat(draft, ",");
});
const oldMapState = new Map<string, number>();
const newMapState = produce(oldMapState, (draft) => {
Immut.table.clear(draft);
if (draft.get("foo") === undefined) draft.set("foo", 1);
});
const oldSetState = new Set<string>();
const newSetState = produce(oldSetState, (draft) => {
Immut.table.clear(draft);
if (!draft.has("foo")) draft.add("foo");
});