Asynchronous JavaScript ☞ http://tech.learn4startup.com/2ac7447150 #Asynchronous #JavaScript
seen from China
seen from Egypt
seen from China

seen from United Kingdom
seen from Morocco
seen from Romania
seen from Greece
seen from Serbia
seen from Tajikistan
seen from Netherlands

seen from Japan

seen from United States

seen from Latvia

seen from Malaysia

seen from Malaysia

seen from Netherlands

seen from Malaysia

seen from United Kingdom
seen from Germany
seen from South Korea
Asynchronous JavaScript ☞ http://tech.learn4startup.com/2ac7447150 #Asynchronous #JavaScript
Asynchronous JavaScript
Asynchronous JavaScript
ABOUT THE COURSE Become an expert in Asynchronous JavaScript, Callbacks, Promises, Async/Await, Generators & The Event Loop
What Will I Learn?
Ace any asynchronous JavaScript interview question
Spend less time chasing down bugs in asynchronous code
Write fast performant JavaScript applications
Understand complex JavaScript concepts
Requirements
Be familiar with `git`…
View On WordPress
“Rethinking Asynchronous JavaScript” by Kyle Simpson
This past week, I began the course “Rethinking Asynchronous JavaScript” given by Kyle Simpson, head of curriculum at MakerSquare and author of You Don’t Know JS series. Unlike other workshops that focus on how to use a specific technology, Simpson works to build up our conceptual understanding of how JavaScript works before giving us example problems to solve. In the case of this course, he explains several patterns for dealing with asynchronous JavaScript calls, beginning with what is asynchronous versus parallel processing - the two are often conflated.
As he explains, parallel processing is actually the opposite of non-parallel processing. Giving the example of a rollercoaster ride, non-parallel processing is where a single person gets on a ride at once. With parallel processing, 30 people get on the same ride and experience it at the same time. Asynchronous processing is different from both of these. In asynchronous processing, two or more macro-level processes are broken down into micro-level tasks. These micro-level tasks are interwoven and happen at different times, but overall it takes the same amount of time to process both macro-tasks.
In asynchronous processing, micro-level steps happen not in order, but out of order, and the macro-tasks are said to happen concurrently. “Asynchronous patterns”, he tells us, “is a way to manage concurrency patterns,” which can become very complex.
One way to handle concurrency and asynchronous tasks is to use callbacks, but this produces some problems. One familiar problem is what is called callback-hell or the pyramid of doom, but Simpson explains that the real problem with these nested calls is not what they look like, but that it makes our code difficult for coders to reason about and to follow. The main issue with using callbacks to handle concurrency is what is called the inversion of control, which is when we hand over control of one part of our program over to another part of our program hat we don’t control. This exposes a trust point that creates bugs that can emerge in unexpected and surprising ways.
Our brains, Simpson explains, are single threaded at even the highest levels - as we have come to learn, there is no such things as multitasking. Wherever our brain diverges from how JS works, that is where bugs happen. If you write your code more like your brain thinks, there is less divergence and fewer bugs; if you can learn and use patterns that work like your brain thinks, that is the best approach. So we need better patterns with which to handle concurrency.
The rest of the course covers several different solutions to concurrency, and a single problem example is solved in these multiple ways to expose the particular strengths and weaknesses of each approach.
In what follows, Simpson explains a very old pattern that has been around since the 60’s, called thunks, a pattern that underlies modern Promises. Now, Promises is a solution not only to concurrency and managing state in asynchronous Javascript programing, but also the trust point issue. But Promises exposes another set of problems, and Promises is best paired with generators. This will the subject of the rest of the course, which I will cover in a subsequent blog post.
AJAX Facebook Like Button
We recently added Facebook "Like" buttons to each of the product pages, but it significantly slowed down the page so we decided to implement the AJAX version of the Facebook Like Button.
Here are the steps to setup the Like button to load asynchronously:
1. Add the Facebook HTML element to the page:
2. Add Javascript to insert and load the Facebook Developer SDK asynchronously:
3. Add Facebook Open Graph meta tags to your pages so your Facebook Fans will receive clean product names and images for the pages they like. This is an example of what we added for each of the products:
4. Test and validate your Open Graph tags via the Facebook Linter
5. Take a look at your page. It will load just like normal:
Then magically, the Facebook Like button will appear moments later: