@context-action/mutative-core
v0.8.8
Published
Context-Action maintained Mutative core for efficient immutable updates
Maintainers
Readme
@context-action/mutative-core
The Context-Action maintained core implementation of Mutative. It preserves
the upstream Mutative API while carrying the maintained fork fixes from
mineclover/mutative, including lazy
array drafts, nested create() isolation, and the produce alias.
Installation
pnpm add @context-action/mutative-coreUsage
import { produce } from '@context-action/mutative-core';
const next = produce({ count: 0 }, (draft) => {
draft.count += 1;
});Core contracts
- Drafts support plain objects, arrays,
Map, andSet. Unchanged branches retain their original references through copy-on-write finalization. - Pass
enablePatches: trueto receive[nextState, patches, inversePatches]. Set changes are represented as areplacepatch so inverse replay preserves insertion order. - The default patch path is an array. A string JSON Pointer path can only
represent string
Mapkeys and string properties; usingpathAsArray: falsewith numeric/objectMapkeys or Symbol properties throws. Use array paths for those keys. strict: truerejects non-draft replacement values. UserawReturn(value)when an intentional raw replacement is required.unsafe(callback)is the scoped escape hatch for accessing mutable values in strict mode.enableAutoFreeze: truefreezes object, array,Map, andSetshells and blocks their normal mutators. As required by JavaScript collection semantics, a directMap.prototype.set.call(map, ...)/Set.prototype.add.call(...)can still bypass an instance-level guard.
@context-action/mutative is the higher-level Context-Action adapter with
patch helpers and time-travel controls. Most application code should use the
adapter; use this package when the upstream-compatible immutable update API is
needed directly.
Lineage and license
This package contains the MIT-licensed Mutative implementation maintained by the Context-Action project. See LICENSE and the fork changelog for the upstream issue and pull-request work carried forward.
The original project is unadlib/mutative;
the maintained source fork is mineclover/mutative.
The exact imported revision is recorded in UPSTREAM.md.
