-
Notifications
You must be signed in to change notification settings - Fork 20
Docs: Async behavior #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!! 🎉 Left some comments here and there – some are small typos, other suggest alternative ways of exposing things, and a few add additional information which might come in handy.
``` | ||
|
||
Surprisingly, this fails! The reason is although `count` is increased, Vue will not update the DOM until the next "tick" or "render cycle". For this reason, the assertion will be called before Vue updates the DOM. This has to do with the concept of "marcotasks", "microtasks" and the JavaScript Event Loop. You can read more details and see a simple example [here](https://javascript.info/event-loop#macrotasks-and-microtasks). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly, this fails! The reason is although `count` is increased, Vue will not update the DOM until the next "tick" or "render cycle". For this reason, the assertion will be called before Vue updates the DOM. This has to do with the concept of "marcotasks", "microtasks" and the JavaScript Event Loop. You can read more details and see a simple example [here](https://javascript.info/event-loop#macrotasks-and-microtasks). | |
Surprisingly, this fails! The reason is although `count` is increased, Vue will not update the DOM until the next "tick" or "render cycle". For this reason, the assertion will be called before Vue updates the DOM. This has to do with the advanced concepts of "macrotasks", "microtasks" and the JavaScript Event Loop. You can read more details and see a simple example [here](https://javascript.info/event-loop#macrotasks-and-microtasks). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually… should these advanced concepts be mentioned before the "simple" solution of using await
? It might be good to flip them: first the simple solution, and then, if anyone's interested, we can mention micro/macro tasks and add some interesting links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
I dropped a link to an article by you about nextTick
in there as well :)
src/guide/async-suspense.md
Outdated
Implementation details aside, how can we fix this? Vue actually provides a way for us to wait until the DOM is updated: `nextTick`: | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to highlight the appropriate line:
```js | |
```js {7} |
Co-authored-by: Adrià Fontcuberta <[email protected]>
Co-authored-by: Adrià Fontcuberta <[email protected]>
Co-authored-by: Adrià Fontcuberta <[email protected]>
Co-authored-by: Adrià Fontcuberta <[email protected]>
Co-authored-by: Adrià Fontcuberta <[email protected]>
I decided not to write about
<Suspense>
yet, because it's experimental and it doesn't appear to officially be documented anywhere (can you even use it withoutsetup
? I have no idea - and we are sticking to the options API in the docs).