Let's go over some JavaScript promise fundamentals. We'll start with a simple, practical, example of fetching data from an API, to see one of the most common use cases. Then we'll cover the various states of Promises, what they mean, and how to achieve them. I'll show how to use `.then` and `.catch` to get the results of a Promise when it is fulfilled or rejected.
Next, we'll use Quokka to visualize the Promise chain flow, and how `.then` statements are skipped when an error occurs in the chain. With all that understanding, we'll write the API fetch we saw at the start of the video and build upon it by doing some nested Promises fetches. I'll show how to flatten them out after that.
Finally we'll convert what we have to Async Await, to show how it can be easier to reason about more complex Promise situations.
~~~~~~
Resources for tools used in this video:
📕 MDN Promise documentation
developer.mozilla.org/en-US/d...
🎥 Philip Roberts Event Loop video
• What the heck is the e...
🎥 Jake Archibald's Render Loop video
• Jake Archibald on the ...
🔌 Quokka VSCode Extension
marketplace.visualstudio.com/...
~~~~~~
Timestamps:
00:00 - What we'll cover
01:19 - Reviewing the tools
02:25 - The first example
03:58 - Video References
04:28 - Promise States
08:24 - Chaining .then and .catch
16:34 - Quokka for viewing Promise chains
22:50 - Putting together the API fetch
27:40 - Nested Promise fetching and flattening
36:55 - Async Await as an alternative syntax
47:29 - Wrap-up
~~~~~~
Follow Jimmy Cleveland's doings:
twitter: / jimmydcleveland
blog: blog.jimmydc.com/
~~~~~~
#promises #javascript
Негізгі бет Understanding Promises and Async Await in JavaScript
Пікірлер: 29