fixed typos in readme
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Gregory Assasie · committed by Gregory Assasie · parent e4ca0d6 · Browse files · 1 file·+9 added−9 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+9 added−9 removed
- other:+9 added−9 removed
Provenance
- Commit
68f6fb5- Tree
b3e30d8- Author
Gregory Assasie <gregjarvez@gmail.com>- Committer
Gregory Assasie <gregjarvez@gmail.com>- Parent
e4ca0d6
1 file changed+9 added−9 removed
modified:readme.md+9 added-9 removed
123345677891010111213141516161718192020 unmodified lines4142434445454647484922 unmodified lines7273747576767778798067 unmodified lines148149150151152153152153154155156157158159160160# 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 work with immutable state in a more convenient way.Immer (German for: always) is a tiny package that allows you to work with immutable state in a more convenient way.It is based on [_copy-on-write_](https://en.wikipedia.org/wiki/Copy-on-write) mechanism.
The basic idea is that you will apply all your changes to a _draftState_. Which is a proxy of the _currentState_, and once all your mutations are completed, immer will produce the _nextState_ based on the mutations to the draft state. This means that you can interact with your data by simply modifying it, while keeping all the benefits of immutable data.The basic idea is that, you will apply all your changes to a _draftState_, which is a proxy of the _currentState_ and once all your mutations are completed, immer will produce the _nextState_ based on the mutations to the draft state. This means that you can interact with your data by simply modifying it, while keeping all the benefits of immutable data.
<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
20 unmodified lines draftState[1].done = true})```
The interesting thing about `immer` is that `baseState` will be untouched, but that `nextState` will reflect all changes made to `draftState`.The interesting thing about `immer` is that, the `baseState` will be untouched, but the `nextState` will reflect all changes made to `draftState`.
```javascript// the new item is only added to the next state,// base state is unmodified22 unmodified lines
A lot of words; here is a simple example of what difference that 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 just 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) {67 unmodified lines* 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 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 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)