Solve Callback Hell with Composition

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

Many APIs in JavaScript rely on callbacks, so when using APIs together, we end up in deeply nested callbacks AKA "Callback Hell". This course solves callback hell through composition by moving all of the nesting into the internals of our helper functions which can expose a clean API that becomes a list of functions in a pipe.

James
~ 4 months ago

How do we figure out that this is the form that's needed? We invoke nest with the first param as one of the functions we took out but the second param is also nest but this time with two params. It's very confusing how we ended up with the code below plus how the order is figured out. Can anyone explain some more please?

nest(getURL)(nest(timeout)(click))((data) => { console.log(data) })

Alex Jacobs
~ 4 months ago

+1 for it being confusing.

I plan to try to reproduce the steps without looking to try and make a mental map of how this final composition was created

Alex Jacobs
~ 4 months ago

Also just saw that there’s a link in the notes for lesson 8. It points to the next set of lessons where these concepts are built up more gradually

~ 4 months ago

I think it is much harder to read doing this way.

Richard Dyce
~ 4 months ago

+1 for functionA(functionE)(functionB(functionC)(functionD)) being confusing

James
~ 4 months ago

I think it is much harder to read doing this way. I would still like to understand how we get there before simplifying with lodash