api.md
This file
Path
docs/api.md
48 lines · 3.9 KiB · Markdown
Last changed by
Updated docsMichel Weststratebefore adoption895e0cc
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| --- | --- | --- |Updated docsMichel Weststratebefore adoption895e0cc
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
lines 14–15why, one step back14| `createDraft` | Given a base state, creates a mutable draft for which any modifications will be recorded | [Async](async.md) |15| `Draft<T>` | Exposed TypeScript type to convert an immutable type to a mutable type | [TypeScript](typescript.md) |Updated docsMichel Weststratebefore adoption895e0cc
lines 16–19why, one step back16| `enableAllPlugins()` | Enables all plugins mentioned below | [Installation](installation#pick-your-immer-version) |17| `enableES5()` | Enables support for older JavaScript engines, such as Internet Explorer and React Native | [Installation](installation#pick-your-immer-version) |18| `enableMapSet()` | Enables support for `Map` and `Set` collections. | [Installation](installation#pick-your-immer-version) |19| `enablePatches()` | Enables support for JSON patches. | [Installation](installation#pick-your-immer-version) |Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
line 20why, one step back20| `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) |killed hooks, as they leaked mangled properties. Also -145 bytesMichel Weststratebefore adoptionf1918cb
line 21why, one step back21| `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 22–29why, one step back22| `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) |23| `Immutable<T>` | Exposed TypeScript type to convert mutable types to immutable types | |24| `isDraft` | Returns true if the given object is a draft object | |25| `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 | |26| `nothing` | Value that can be returned from a recipe, to indicate that the value `undefined` should be produced | [Return](return.md) |27| `original` | Given a draft object (doesn't have to be a tree root), returns the the original object at the same path in the original state tree, if present | [Original](original.md) |28| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](patches.md) |29| `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 30why, one step back30| `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 31why, one step back31| `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 32–48why, one step back32| `setUseProxies` | Can be used to disable or force the use of `Proxy` objects. Useful when filing bug reports. | |3334## Importing immer3536`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:3738```javascript39import produce from "immer"40import {produce} from "immer"4142const {produce} = require("immer")43const produce = require("immer").produce44const produce = require("immer").default4546import unleashTheMagic from "immer"47import {produce as unleashTheMagic} from "immer"48```