Skip to content
Myr

docs: elaborate on immerable symbol

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

Closes #341

authored by Alec Larson · committed by GitHub · parent dfcd543 · Browse files · 1 file+17 added−1 removed
This commit

State

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

Diff stats

1 file+17 added−1 removed

  • other:+17 added−1 removed

1 file+17 added−1 removed

modified:readme.md+17 added-1 removed
524 unmodified lines
525```526527## Supported object types528529Only plain objects and arrays are automatically drafted by Immer. This means other object types should never be mutated **unless** you added the exported `immerable` symbol to the object itself, its prototype, or its class constructor. In that case, the object is essentially an immutable plain object with a custom prototype.529Plain objects and arrays are always drafted by Immer.530531Every 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.532533```js534import {immerable} from 'immer'535536class Foo {537 [immerable] = true // Option 1538539 constructor() {540 this[immerable] = true // Option 2541 }542}543544Foo[immerable] = true // Option 3545```546547For arrays, only numeric properties and the `length` property can be mutated. Custom properties are not preserved on arrays.548549When working with `Date` objects, you should always create a new `Date` instance instead of mutating an existing `Date` object.550
227 unmodified lines