complex-objects.md
This file
Path
docs/complex-objects.md
30 lines · 1007 bytes · Markdown
Last changed by
Updated docs. Also fixes #445Michel Weststratebefore adoption7335671
History of this fileTake it
Merge branch 'master' into v4Michel Weststratebefore adoption741e941
lines 1–7why, one step back1---2id: complex-objects3title: Working with classes4---56<div id="codefund"><!-- fallback content --></div>7Updated docs. Also fixes #445Michel Weststratebefore adoption7335671
line 8why, one step back8Plain objects, arrays, `Map`s and `Set`s are always drafted by Immer.Merge branch 'master' into v4Michel Weststratebefore adoption741e941
lines 9–29why, one step back910Every other object must use the `immerable` symbol to mark itself as compatible with Immer. When one of these objects is mutated within a producer, its prototype is preserved between copies.1112```js13import {immerable} from "immer"1415class Foo {16 [immerable] = true // Option 11718 constructor() {19 this[immerable] = true // Option 220 }21}2223Foo[immerable] = true // Option 324```2526For arrays, only numeric properties and the `length` property can be mutated. Custom properties are not preserved on arrays.2728When working with `Date` objects, you should always create a new `Date` instance instead of mutating an existing `Date` object.29Updated docs. Also fixes #445Michel Weststratebefore adoption7335671
line 30why, one step back30Maps and Sets that are produced by Immer will be made artificially immutable. This means that they will throw an exception when trying mutative methods like `set`, `clear` etc. outside a producer.