Skip to content
Myr

api.md

This file

Path

docs/api.md

40 lines · 3.0 KiB · Markdown

Last changed by

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

History of this file

Take it

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 1–13why, one step back
1---
2id: api3title: API overview4---56<div id="codefund"><!-- fallback content --></div>78| Exported name | Description | Section |9| --- | --- | --- |10| `applyPatches` | Given a base state or draft, and a set of patches, applies the patches | [Patches](patches.md) |11| `createDraft` | Given a base state, creates a mutable draft for which any modifications will be recorded | [Async](async.md) |12| `Draft<T>` | Exposed TypeScript type to convert an immutable type to a mutable type | [TypeScript](typescript.md) |13| `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 #443 from Mudassar045/fix-grammatical-typosMichel Weststratebefore adoption0349152

line 14why, one step back
14| `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. Can also be used to attach further hooks that are triggered during object finalization, such as `onAssign`, `onDelete` and `onCopy`. | [See source](https://github.com/immerjs/immer/blob/cb1c6dd8a33073aaa0a4d881c94ec7ab1c1be7f6/src/immer.d.ts#L224-L233) |

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 15–22why, one step back
15| `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) |
16| `Immutable<T>` | Exposed TypeScript type to convert mutable types to immutable types | |17| `isDraft` | Returns true if the given object is a draft object | |18| `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 | |19| `nothing` | Value that can be returned from a recipe, to indicate that the value `undefined` should be produced | [Return](return.md) |20| `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) |21| `Patch` | Exposed TypeScript type, describes the shape of an (inverse) patch object | [Patches](patches.md) |22| `produce` | The core API of Immer, also exposed as the `default` export | [Produce](produce.md) |

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

line 23why, one step back
23| `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 24–40why, one step back
24| `setUseProxies` | Can be used to disable or force the use of `Proxy` objects. Useful when filing bug reports. | |
2526## Importing immer2728`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:2930```javascript31import produce from "immer"32import {produce} from "immer"3334const {produce} = require("immer")35const produce = require("immer").produce36const produce = require("immer").default3738import unleashTheMagic from "immer"39import {produce as unleashTheMagic} from "immer"40```