He created this CodeSandBox as a demonstration. The lecture goes through fulfilling this capability via CallBacks, then Promises and finally Await/Async.
I must say, Callbacks, Promises and Async/Await are clearer to me now. Some key takeaways:
- Callbacks force on to think non-sequentially.
- Callback Hell is a problem: the idea; nested callbacks have bad readability.
This can be improved by making code modular; but one still has callback hell.
- Callbacks also have inversion of control issue. When you ask a 3rd party to invoke a callback, you defer control to them and trust them to pass the appropriate parameters.
- Promises are designed to improve this.
- Promises are created by creating a new instance of a Promise().
- Promises take a callback with an object that is passed to arguments: resolve (fulfilled) and reject (rejected).
- "One thing we haven’t talked about yet is what a promise actually is. When you create a
catch. Here’s the key. When the status of the promise changes to
fulfilled, the function that was passed to
.thenwill get invoked. When the status of a promise changes to
rejected, the function that was passed to
.catchwill be invoked."
There's more, and I should re-review the Asysc/Await stuff. It was easy to follow, so my notes and established understanding is a bit light.