$ show unadlib/mutative
Mutative is a high-performance JavaScript/TypeScript library for immutable state updates using a mutable syntax, similar to Immer but with significantly better performance (claimed 2-6x faster than naive reducers, >10x faster than Immer). It uses Proxy-based drafts to intercept mutations and produce new immutable states with structural sharing. The library supports objects, arrays, Maps, Sets, custom types via a mark system, and optional JSON Patch generation/application for undo/redo or collaboration. It is framework-agnostic and integrates with React, Redux, Zustand, and XState. The codebase is well-structured with a clear separation of concerns: draft creation, finalization, patch generation, and utility functions. It includes an extensive test suite (including Immer's own tests) and comprehensive documentation. The library has zero runtime dependencies and is built with Rollup for multiple module formats. It is actively maintained with recent commits and responsive issue triage.
The LLM identified 3 files worth highlighting for reuse:
Generates JSON Patch (RFC 6902) operations from a set of recorded mutations on a draft. It produces both forward and inverse patches, supporting objects, arrays, Maps, Sets, and nested structures. The module is self-contained and could be extracted as a standalone library for computing diffs between two states. It handles edge cases like array length changes, reference sharing, and same-value replacement (empty patches).
Applies an array of JSON Patch operations to a target state, producing a new immutable state (or optionally mutating in place). Supports all standard operations (add, remove, replace) and handles arrays, objects, Maps, Sets, and custom types. The module is independent of the draft system and could be reused in any project needing patch application, such as collaborative editing or undo/redo systems.
Deeply freezes an object tree, with optional circular reference detection in development mode. It recursively freezes all properties, including Maps and Sets, and handles non-enumerable and symbol properties. This utility is self-contained and could be reused in any project requiring deep immutability enforcement, such as state management or data validation.