Skip to content
Myr

api.md

This file

Path

docs/api.md

51 lines · 4.1 KiB · Markdown

Last changed by

docs: updated sponsor linksMichel Weststratebefore adoptionf97d037

History of this file

Take it

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 1–5why, one step back
1---
2id: api3title: API overview4---5

docs: updated sponsor linksMichel Weststratebefore adoptionf97d037

lines 6–8why, one step back
6<center>
7<div data-ea-publisher="immerjs" data-ea-type="image" class="horizontal bordered"></div>8</center>

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 9–11why, one step back
9
10| Exported name | Description | Section |11| --- | --- | --- |

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

line 12why, one step back
12| `(default)` | The core API of Immer, typically named `produce`: `import produce from "immer"` | [Produce](produce.md) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

line 13why, one step back
13| `applyPatches` | Given a base state or draft, and a set of patches, applies the patches | [Patches](patches.md) |

feat: general typing improvements for TS 3.7 and upMichel Weststratebefore adoptionf930ce1

lines 14–15why, one step back
14| `castDraft` | Converts any immutable type to its mutable counterpart. This is just a cast and doesn't actually do anything. | [TypeScript](typescript.md) |
15| `castImmutable` | Converts any mutable type to its immutable counterpart. This is just a cast and doesn't actually do anything. | [TypeScript](typescript.md) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

line 16why, one step back
16| `createDraft` | Given a base state, creates a mutable draft for which any modifications will be recorded | [Async](async.md) |

Immer 7Michel Weststratebefore adoption467ea5d

line 17why, one step back
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) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

line 18why, one step back
18| `Draft<T>` | Exposed TypeScript type to convert an immutable type to a mutable type | [TypeScript](typescript.md) |

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 19–22why, one step back
19| `enableAllPlugins()` | Enables all plugins mentioned below | [Installation](installation#pick-your-immer-version) |
20| `enableES5()` | Enables support for older JavaScript engines, such as Internet Explorer and React Native | [Installation](installation#pick-your-immer-version) |21| `enableMapSet()` | Enables support for `Map` and `Set` collections. | [Installation](installation#pick-your-immer-version) |22| `enablePatches()` | Enables support for JSON patches. | [Installation](installation#pick-your-immer-version) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

line 23why, one step back
23| `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.md) |

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

line 24why, one step back
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. |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 25–29why, one step back
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.md) |

Merge pull request #621 from NoriSte/masterMichel Weststratebefore adoptione8639dc

line 30why, one step back
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) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 31–32why, one step back
31| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](patches.md) |
32| `produce` | The core API of Immer, also exposed as the `default` export | [Produce](produce.md) |

feat: added first class support for `Map` and `Set`Michel Weststratebefore adoptionb6f1d40

line 33why, one step back
33| `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.md) |

Merge pull request #443 from Mudassar045/fix-grammatical-typosMichel Weststratebefore adoption0349152

line 34why, one step back
34| `setAutoFreeze` | Enables / disables automatic freezing of the trees produces. By default enabled in development builds | [Freezing](freezing.md) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 35–51why, one step back
35| `setUseProxies` | Can be used to disable or force the use of `Proxy` objects. Useful when filing bug reports. | |
3637## Importing immer3839`produce` is exposed as the default export, but optionally it can be used as name import as well, as this benefits some older project setups. So the following imports are all correct, where the first is recommended:4041```javascript42import produce from "immer"43import {produce} from "immer"4445const {produce} = require("immer")46const produce = require("immer").produce47const produce = require("immer").default4849import unleashTheMagic from "immer"50import {produce as unleashTheMagic} from "immer"51```