Mutative is a JavaScript library designed for performing efficient immutable updates on data structures, drawing inspiration from libraries like Immer but with a strong focus on performance. It allows developers to write 'mutative' logic inside a producer function, and Mutative handles the underlying copy-on-write mechanism to return a new, immutably updated state. The library is currently at version 1.3.0 and exhibits an active release cadence, with frequent patch and minor updates. Key differentiators include its reported performance benefits, claiming to be 2-6x faster than naive handcrafted reducers using spread operators and over 10x faster than Immer, primarily through shallow copy optimization, lazy drafts, and an optimized finalization process. It aims to address issues like Immer's mandatory auto-freeze and improve type inference and handling of various immutability edge cases.
npm install mutativeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `create` to immutably update nested objects and arrays, showcasing efficient partial updates and reference preservation for unchanged parts.
Always benchmark Mutative against your specific use cases and existing update patterns to confirm actual performance benefits in your application.
Encapsulate all state mutation logic within the `create` callback. Treat the object returned by `create` as strictly immutable.
Upgrade to the latest stable version of Mutative (v1.1.0 or newer) to ensure reliable and correct functionality of the `current()` API.
Thoroughly test Mutative with any custom classes or non-standard JavaScript objects in your state. For complex scenarios, inspect the `original()` reference or the final state to ensure expected immutability and data integrity.
Ensure all modifications to the draft state are confined within the producer function passed to `create`. Do not store or attempt to modify the `draft` object reference after `create` returns.
Always use the `create` function with a producer callback to make changes. The return value of `create` is the new, immutable state.
For ES Modules, use `import { create } from 'mutative'`. For CommonJS in environments where it's supported, use `const { create } = require('mutative')`.No dependency data recorded yet.