Grammar tweaks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Matt Ruby · committed by GitHub · parent 101aac2 · Browse files · 1 file·+10 added−10 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+10 added−10 removed
- other:+10 added−10 removed
Provenance
- Commit
9c88ddb- Tree
56fa16d- Author
Matt Ruby <mattruby@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
101aac2
1 file changed+10 added−10 removed
modified:readme.md+10 added-10 removed
123345674 unmodified lines1213141516161718192048 unmodified lines697071727373747576767778798057 unmodified lines138139140141142142143144145146147148147148149150151152153152153154155156157158159160160# Immer
_Your personally assistance for creating your next immutable state__Your personal assistant for creating your next immutable state_
---
Immer (German for: always) is a tiny package that allows you to work with immutable state in a more convenient way.4 unmodified lines<center>

Using immer is like having a personal assistant; he takes a letter (the current state), and gives you a copy (draft) to jod changes onto. Once you are done the assistant will take your draft and produce the real immutable, final letter for you (the next state).Using immer is like having a personal assistant; he takes a letter (the current state), and gives you a copy (draft) to jot changes onto. Once you are done, the assistant will take your draft and produce the real immutable, final letter for you (the next state).</center>
## API
48 unmodified lines* No accidental mutations of current state, but intentional mutations of a draft state
## Reducer Example
A lot of words; here is a simple example of what difference that could make in practice.A lot of words; here is a simple example of the difference that this approach could make in practice.The todo reducers from the official Redux [todos-with-undo example](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/todos-with-undo)
_Note, this is just a sample application of the `immer` package. Immer is design to just simply Redux reducers. It can be used in any context where you have an immutable data tree that you want to clone and modify (with structural sharing)__Note, this is just a sample application of the `immer` package. Immer is designed to simplify Redux reducers. It can be used in any context where you have an immutable data tree that you want to clone and modify (with structural sharing)_
```javascriptconst todo = (state, action) => { switch (action.type) {57 unmodified lines } })```
Creating middleware or reducer wrapper that applies `immer` automatically is left as exercise to the reader :-).Creating middleware or a reducer wrapper that applies `immer` automatically is left as exercise for the reader :-).
## Limitations
* This package requires Proxies, so Safari > 10, no Internet Explorer* Currently only tree shaped states are supported. Cycles could potentially be supported as well (PR's welcome)* Currently only supports plain objects and arrays. Non-plain data structures (like `Map`, `Set`) not (yet). (PR's welcome)* Currently, only tree shaped states are supported. Cycles could potentially be supported as well (PR's welcome)* Currently, only supports plain objects and arrays. Non-plain data structures (like `Map`, `Set`) not (yet). (PR's welcome)
## Pitfalls:
* Make sure to modify the state you get passed in in the callback function, not the original base state that was passed as first argument to `immer`!* Since immer uses proxies, reading huge amounts of data from state comes with an overhead. If this ever becomes an issue (measure before optimize!), do the current state analysis before entering the `immer` block or read form the `currentState` rather than the `draftState`* Make sure to modify the state you get passed in in the callback function, not the original base state that was passed as the first argument to `immer`!* Since immer uses proxies, reading huge amounts of data from state comes with overhead. If this ever becomes an issue (measure before you optimize!), do the current state analysis before entering the `immer` block or read from the `currentState` rather than the `draftState`
## Changelog
### 0.0.4 (31-12-2017)
* Added typescript typings [#11](https://github.com/mweststrate/immer/pull/11) by [@benbraou](https://github.com/benbraou)* Fixed bug when setting properties to `undefined`. Fixes [#12](https://github.com/mweststrate/immer/issues/12) through [#13](https://github.com/mweststrate/immer/pull/13) by [@benbraou](https://github.com/benbraou)No newline at end of file* Fixed bug when setting properties to `undefined`. Fixes [#12](https://github.com/mweststrate/immer/issues/12) through [#13](https://github.com/mweststrate/immer/pull/13) by [@benbraou](https://github.com/benbraou)