api.md
This file
Path
docs/api.md
49 lines · 4.0 KiB · Markdown
Last changed by
Merge pull request #621 from NoriSte/masterMichel Weststratebefore adoptione8639dc
History of this fileTake it
Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 1–9why, one step back1---2id: api3title: API overview4---56<div id="codefund"><!-- fallback content --></div>78| Exported name | Description | Section |9| --- | --- | --- |Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 10why, one step back10| `(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 11why, one step back11| `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 12–13why, one step back12| `castDraft` | Converts any immutable type to its mutable counterpart. This is just a cast and doesn't actually do anything. | [TypeScript](typescript.md) |13| `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 14why, one step back14| `createDraft` | Given a base state, creates a mutable draft for which any modifications will be recorded | [Async](async.md) |Immer 7Michel Weststratebefore adoption467ea5d
line 15why, one step back15| `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 16why, one step back16| `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 17–20why, one step back17| `enableAllPlugins()` | Enables all plugins mentioned below | [Installation](installation#pick-your-immer-version) |18| `enableES5()` | Enables support for older JavaScript engines, such as Internet Explorer and React Native | [Installation](installation#pick-your-immer-version) |19| `enableMapSet()` | Enables support for `Map` and `Set` collections. | [Installation](installation#pick-your-immer-version) |20| `enablePatches()` | Enables support for JSON patches. | [Installation](installation#pick-your-immer-version) |Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
line 21why, one step back21| `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 22why, one step back22| `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 23–27why, one step back23| `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) |24| `Immutable<T>` | Exposed TypeScript type to convert mutable types to immutable types | |25| `isDraft` | Returns true if the given object is a draft object | |26| `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 | |27| `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 28why, one step back28| `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 29–30why, one step back29| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](patches.md) |30| `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 31why, one step back31| `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 32why, one step back32| `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 33–49why, one step back33| `setUseProxies` | Can be used to disable or force the use of `Proxy` objects. Useful when filing bug reports. | |3435## Importing immer3637`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:3839```javascript40import produce from "immer"41import {produce} from "immer"4243const {produce} = require("immer")44const produce = require("immer").produce45const produce = require("immer").default4647import unleashTheMagic from "immer"48import {produce as unleashTheMagic} from "immer"49```