installation.mdx
This file
Path
website/docs/installation.mdx
82 lines · 4.2 KiB
Last changed by
docs: add Deno to install instructions (#1252)Bartek Iwańczukbefore adoption420ca51
History of this fileTake it
The walk stopped after 200 commits: lines older than 07f5cc9 point at it.
chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 1–17why, one step back1---2id: installation3title: Installation4---56<center>7 <div8 data-ea-publisher="immerjs"9 data-ea-type="image"10 className="horizontal bordered"11 ></div>12</center>1314Immer can be installed as a direct dependency, and will work in any ES5 environment:1516- Yarn: `yarn add immer`17- NPM: `npm install immer`docs: add Deno to install instructions (#1252)Bartek Iwańczukbefore adoption420ca51
line 18why, one step back18- Deno: `deno install immer`chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 19–21why, one step back19- CDN: Exposed global is `immer`20 - Unpkg: `<script src="https://unpkg.com/immer"></script>`21 - JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/immer"></script>`docs: Update installation.mdx (#1084)Muhammad Mukhtar Suleimanbefore adoptiona73ebf3
line 22why, one step back22 - ⚠️ When using a CDN, it is best to check the url in your browser and see what version it resolves to, so that your users aren't accidentally served a newer version in the future when updates are release. So use a url like: https://unpkg.com/immer@6.0.3/dist/immer.umd.production.min.js instead. Substitute `production.min` with `development` in the URL for a development build.chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 23–33why, one step back2324## Pick your Immer version2526_This section only applies to version 6 and later_2728To make sure Immer is as small as possible, features that are not required by every project has been made opt-in, and have to be enabled explicitly. This ensures that when bundling your application for production, unused features don't take any space.2930The following features can be opt-in to:3132| Feature | Description | Method to call |33| --- | --- | --- |feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
line 34why, one step back34| [Array Methods optimization](./array-methods.md) | Optimizes array method handling for improved performance with array-heavy operations | `enableArrayMethods()` |chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 35–46why, one step back35| [ES2015 Map and Set support](./complex-objects.md) | To enable Immer to operate on the native `Map` and `Set` collections, enable this feature | `enableMapSet()` |36| [JSON Patch support](./patches.mdx) | Immer can keep track of all the changes you make to draft objects. This can be useful for communicating changes using JSON patches | `enablePatches()` |3738For example, if you want to use `produce` on a `Map`, you need to enable this feature once during the start of your application:3940```typescript41// In your application's entrypoint42import {enableMapSet} from "immer"4344enableMapSet()4546// ...laterMerge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 47why, one step back47import {produce} from "immer"chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 48–60why, one step back4849const usersById_v1 = new Map([50 ["michel", {name: "Michel Weststrate", country: "NL"}]51])5253const usersById_v2 = produce(usersById_v1, draft => {54 draft.get("michel").country = "UK"55})5657expect(usersById_v1.get("michel").country).toBe("NL")58expect(usersById_v2.get("michel").country).toBe("UK")59```60feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
line 61why, one step back61Vanilla Immer kicks in at ~3KB gzipped. Every plugin that is enabled adds ~1-2 KB to that. The breakdown is as follows:chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 62–65why, one step back6263```64Import size report for immer:65┌───────────────────────┬───────────┬────────────┬───────────┐feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
line 66why, one step back66│ (index) │ just this │ cumulative │ increment │chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 67why, one step back67├───────────────────────┼───────────┼────────────┼───────────┤feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
lines 68–72why, one step back68│ import * from 'immer' │ 6908 │ 0 │ 0 │69│ produce │ 4183 │ 4183 │ 0 │70│ enableMapSet │ 4971 │ 4980 │ 797 │71│ enablePatches │ 5335 │ 6097 │ 1117 │72│ enableArrayMethods │ 4768 │ 6659 │ 562 │chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 73–80why, one step back73└───────────────────────┴───────────┴────────────┴───────────┘74(this report was generated by npmjs.com/package/import-size)75```7677## Immer on older JavaScript environments?7879By default `produce` tries to use proxies for optimal performance. However, on older JavaScript engines `Proxy` is not available. For example, when running Microsoft Internet Explorer or React Native (if < v0.59 or when using the Hermes engine on React Native < 0.64) on Android. In such cases, Immer will fallback to an ES5 compatible implementation which works identically, but is a bit slower.80Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 81–82why, one step back81- Since version 6, support for the fallback implementation has to be explicitly enabled by calling `enableES5()`.82- Version 10 drops the fallback implementation fully, and cannot be used in browsers / engines that don't support Proxy.