Skip to content

Commit

Permalink
docs: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Feb 2, 2019
1 parent 3b8b39f commit 9c498e1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Tip: Check this trick to [compress patches](https://medium.com/@david.b.edelstei

## Async producers

It is allowed to return Promise objects from recipes. Or, in other words, to use `async / await`. This can be pretty useful for long running processes, that only produce the new object once the promise chain resolves. Note that `produce` itself (even in the curried form) itself will return a promise if the producer is async. Example:
It is allowed to return Promise objects from recipes. Or, in other words, to use `async / await`. This can be pretty useful for long running processes, that only produce the new object once the promise chain resolves. Note that `produce` itself (even in the curried form) will return a promise if the producer is async. Example:

```javascript
import produce from "immer"
Expand All @@ -347,8 +347,8 @@ const user = {
todos: []
}

const loadedUser = await produce(users, async function(draft) {
user.todos = await window.fetch("http://host/" + draft.name).json()
const loadedUser = await produce(user, async function(draft) {
user.todos = await (await window.fetch("http://host/" + draft.name)).json()
})
```

Expand All @@ -359,15 +359,15 @@ _Warning: please note that the draft shouldn't be 'leaked' from the async proces
`createDraft` and `finishDraft` are two low-level functions that are mostly useful for libraries that build abstractions on top of immer. It avoids the need to always create a function in order to work with drafts. Instead, one can create a draft, modify it, and at some time in the future finish the draft, in which case the next immutable state will be produced. We could for example rewrite our above example as:

```javascript
import { createDraft, finishDraft } from "immer"
import {createDraft, finishDraft} from "immer"

const user = {
name: "michel",
todos: []
}

const draft = createDraft(user)
const draft.todos = await window.fetch("http://host/" + draft.name).json()
draft.todos = await (await window.fetch("http://host/" + draft.name)).json()
const loadedUser = finishDraft(draft)
```

Expand Down

0 comments on commit 9c498e1

Please sign in to comment.