api.md
This file
Path
website/docs/api.md
45 lines · 4.2 KiB · Markdown
Last changed by
[docs] Documented setUseStrictIterationMichel Weststratebefore adoptionbdf5cbd
History of this fileTake it
The walk stopped after 200 commits: lines older than 3f9a94e point at it.
chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 1–6why, one step back1---2id: api3title: API overview4---56<center>chore: docusaurus upgradeMichel Weststratebefore adoption48a91b3
line 7why, one step back7<div data-ea-publisher="immerjs" data-ea-type="image" className="horizontal bordered"></div>chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 8–11why, one step back8</center>910| Exported name | Description | Section |11| --- | --- | --- |Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 12why, one step back12| `produce` | The core API of Immer: `import {produce} from "immer"` | [Produce](./produce.mdx) |chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 13–18why, one step back13| `applyPatches` | Given a base state or draft, and a set of patches, applies the patches | [Patches](./patches.mdx) |14| `castDraft` | Converts any immutable type to its mutable counterpart. This is just a cast and doesn't actually do anything. | [TypeScript](./typescript.mdx) |15| `castImmutable` | Converts any mutable type to its immutable counterpart. This is just a cast and doesn't actually do anything. | [TypeScript](./typescript.mdx) |16| `createDraft` | Given a base state, creates a mutable draft for which any modifications will be recorded | [Async](./async.mdx) |17| `current` | Given a draft object (doesn't have to be a tree root), takes a snapshot of the current state of the draft | [Current](./current.md) |18| `Draft<T>` | Exposed TypeScript type to convert an immutable type to a mutable type | [TypeScript](./typescript.mdx) |feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
line 19why, one step back19| `enableArrayMethods()` | Enables optimized array method handling for improved performance with array-heavy operations. | [Array Methods](./array-methods.md) |chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 20–33why, one step back20| `enableMapSet()` | Enables support for `Map` and `Set` collections. | [Installation](./installation.mdx#pick-your-immer-version) |21| `enablePatches()` | Enables support for JSON patches. | [Installation](./installation#pick-your-immer-version) |22| `finishDraft` | Given an draft created using `createDraft`, seals the draft and produces and returns the next immutable state that captures all the changes | [Async](./async.mdx) |23| `freeze(obj, deep?)` | Freezes draftable objects. Returns the original object. By default freezes shallowly, but if the second argument is `true` it will freeze recursively. |24| `Immer` | constructor that can be used to create a second "immer" instance (exposing all APIs listed in this instance), that doesn't share its settings with global instance. |25| `immerable` | Symbol that can be added to a constructor or prototype, to indicate that Immer should treat the class as something that can be safely drafted | [Classes](./complex-objects.md) |26| `Immutable<T>` | Exposed TypeScript type to convert mutable types to immutable types | |27| `isDraft` | Returns true if the given object is a draft object | |28| `isDraftable` | Returns true if Immer is capable of turning this object into a draft. Which is true for: arrays, objects without prototype, objects with `Object` as their prototype, objects that have the `immerable` symbol on their constructor or prototype | |29| `nothing` | Value that can be returned from a recipe, to indicate that the value `undefined` should be produced | [Return](./return.mdx) |30| `original` | Given a draft object (doesn't have to be a tree root), returns the original object at the same path in the original state tree, if present | [Original](./original.md) |31| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](./patches.mdx) |32| `produceWithPatches` | Works the same as `produce`, but instead of just returning the produced object, it returns a tuple, consisting of `[result, patches, inversePatches]`. | [Patches](./patches.mdx) |33| `setAutoFreeze` | Enables / disables automatic freezing of the trees produces. By default enabled. | [Freezing](./freezing.mdx) |Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 34why, one step back34| `setUseStrictShallowCopy` | Can be used to enable strict shallow copy. If enable, immer copies non-enumerable properties as much as possible. | [Classes](./complex-objects.md) |[docs] Documented setUseStrictIterationMichel Weststratebefore adoptionbdf5cbd
line 35why, one step back35| `setUseStrictIteration` | Controls iteration behavior: pass `false` for loose iteration (enumerable properties only, better performance) or `true` for strict iteration (includes symbols and non-enumerable properties). By default disabled (loose iteration). | |chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 36–38why, one step back3637## Importing immer38Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 39why, one step back39In most cases, the only thing you need to import from Immer is `produce`:chore: let's test before publishMichel Weststratebefore adoption3f9a94e
lines 40–43why, one step back4041```javascript42import {produce} from "immer"43```Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 44–45why, one step back4445Note that in older versions, `produce` was also available as default export (e.g. `import produce from "immer"` was also valid, but that is no longer the case to improve eco system compatibility.