Skip to content
Myr

docs(zh-CN): update installation guide for current features (#1307)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Hugohong258 · committed by GitHub · parent a808da8 · Browse files · 1 file+11 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Hugohong258 <282228220+Hugohong258@users.noreply.github.com>

Diff stats

1 file+11 added−9 removed

  • other:+11 added−9 removed

1 file+11 added−9 removed

modified:website/i18n/zh-CN/docusaurus-plugin-content-docs/current/installation.mdx+11 added-9 removed
9 unmodified lines
10 className="horizontal bordered"11 ></div>12</center>1314Immer 可以作为直接依赖项安装,并且可以在任何 ES5 环境中工作:14Immer 可以作为直接依赖项安装:1516- Yarn: `yarn add immer`17- NPM: `npm install immer`18- Deno: `deno install immer`19- CDN: 暴露的全局变量是 `immer`20 - Unpkg: `<script src="https://unpkg.com/immer"></script>`21 - JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/immer"></script>`22 - ⚠️ 使用 CDN 时,最好检查浏览器中的 url 并查看它解析为哪个版本,这样当更新发布时,您的用户不会意外地获得更新的版本。因此,请改用如下网址:https://unpkg.com/immer@6.0.3/dist/immer.umd.production.min.js 。在 URL 中将 production.min 替换为 development 以进行开发构建。
7 unmodified lines
30可以选择加入以下功能:3132| 功能 | 描述 | 调用方法 |33| --- | --- | --- |33| ES 5 支持 | 如果您的应用程序需要能够在较旧的 JavaScript 环境(例如 Internet Explorer 或 React Native)上运行,请启用此功能。 | `enableES5()` |34| [数组方法优化](./array-methods.md) | 优化数组方法的处理,提升大量数组操作的性能 | `enableArrayMethods()` |35| [ES2015 Map and Set 支持](./complex-objects.md) | 要使 Immer 能够对原生 Map 和 Set 集合进行操作,请启用此功能 | `enableMapSet()` |36| [JSON 补丁 支持](./patches.mdx) | Immer 可以跟踪您对 draft 对象所做的所有更改。这对于使用 JSON 补丁时传达更改很有用 | `enablePatches()` |3738例如,如果您想在 `Map` 上使用 `produce` ,则需要在应用程序启动期间启用此功能一次:
18 unmodified lines
57expect(usersById_v1.get("michel").country).toBe("NL")58expect(usersById_v2.get("michel").country).toBe("UK")59```6060Immer 以大约 3KB 的 gzip 压缩开始。每个启用的插件都会增加 < 1 KB。细分如下61基础版 Immer 经 gzip 压缩后约为 3 KB。每启用一个插件,大小约增加 1–2 KB。具体如下:6263```64Import size report for immer:65┌───────────────────────┬───────────┬────────────┬───────────┐65│ (index) │ just this │ cumulative │ increment │66│ (index) │ just this │ cumulative │ increment │67├───────────────────────┼───────────┼────────────┼───────────┤67│ import * from 'immer' │ 5033 │ 0 │ 0 │68│ produce │ 3324 │ 3324 │ 0 │69│ enableMapSet │ 4030 │ 4039 │ 715 │70│ enablePatches │ 4112 │ 4826 │ 787 │68│ 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 │73└───────────────────────┴───────────┴────────────┴───────────┘74(this report was generated by npmjs.com/package/import-size)75```76
1 unmodified line
7879默认情况下,`produce` 尝试使用代理以获得最佳性能。但是,在较旧的 JavaScript 引擎上,代理不可用。例如,在 Android 上运行 Microsoft Internet Explorer 或 React Native(如果 React Native < v0.59 或在 React Native < v0.64 上使用 Hermes 引擎)时。在这种情况下,Immer 将回退到与 ES5 兼容的实现,其工作方式相同,但速度稍慢8081- 从版本 6 开始,必须通过调用 `enableES5()` 显式启用对回退实现的支持80- Version 10 drops the fallback implementation fully, and cannot be used in browsers / engines that don't support Proxy.82- 从版本 10 开始,Immer 完全移除了备用实现,因此不能在不支持 `Proxy` 的浏览器或 JavaScript 引擎中使用。