api.md
This file
Path
docs/api.md
52 lines · 4.2 KiB · Markdown
Last changed by
feature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f
History of this fileTake it
Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 1–5why, one step back1---2id: api3title: API overview4---5docs: updated sponsor linksMichel Weststratebefore adoptionf97d037
lines 6–8why, one step back6<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 back910| Exported name | Description | Section |11| --- | --- | --- |Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 12why, one step back12| `(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 back13| `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 back14| `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 back16| `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 back17| `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 back18| `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 back19| `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 back23| `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) |feature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f
line 24why, one step back24| `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. |Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 25why, one step back25| `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 26–30why, one step back26| `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) |27| `Immutable<T>` | Exposed TypeScript type to convert mutable types to immutable types | |28| `isDraft` | Returns true if the given object is a draft object | |29| `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 | |30| `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 31why, one step back31| `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 32–33why, one step back32| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](patches.md) |33| `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 34why, one step back34| `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) |feature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f
line 35why, one step back35| `setAutoFreeze` | Enables / disables automatic freezing of the trees produces. By default enabled. | [Freezing](freezing.md) |Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 36–52why, one step back36| `setUseProxies` | Can be used to disable or force the use of `Proxy` objects. Useful when filing bug reports. | |3738## Importing immer3940`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:4142```javascript43import produce from "immer"44import {produce} from "immer"4546const {produce} = require("immer")47const produce = require("immer").produce48const produce = require("immer").default4950import unleashTheMagic from "immer"51import {produce as unleashTheMagic} from "immer"52```