freezing.mdx
This file
Path
website/docs/freezing.mdx
40 lines · 1.6 KiB
Last changed by
chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
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–11why, one step back1---2id: freezing3title: Auto freezing4---56<center>7 <div8 data-ea-publisher="immerjs"9 data-ea-type="image"10 className="horizontal bordered"11 ></div>chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 12–13why, one step back12</center>13<details>chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 14–40why, one step back14 <summary className="egghead-summary">15 egghead.io lesson 7: Immer automatically freezes data16 </summary>17 <br />18 <div>19 <iframe20 width="760"21 height="427"22 scrolling="no"23 src="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer/embed"24 ></iframe>25 </div>26 <a27 className="egghead-link"28 href="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer"29 >30 Hosted on egghead.io31 </a>32</details>3334Immer automatically freezes any state trees that are modified using `produce`. This protects against accidental modifications of the state tree outside of a producer. In most cases this provides the most optimal behavior, but `setAutoFreeze(true / false)` can be used to explicitly turn this feature on or off.3536Immer will never freeze (the contents of) non-enumerable, non-own or symbolic properties, unless their content was drafted.3738_⚠️ Immer freezes everything recursively, for large data objects that won't be changed in the future this might be over-kill, in that case it can be more efficient to shallowly pre-freeze data using the `freeze` utility.⚠️_3940_⚠️ If auto freezing is enabled, recipes are not entirely side-effect free: Any plain object or array that ends up in the produced result, will be frozen, even when these objects were not frozen before the start of the producer! ⚠️_