, 6 tweets, 5 min read Read on Twitter
👁️👁️Watch me refactor an simple API in four simple steps. (a twitter thread). ⚠️Warning, may contain currying and partial application 😉
#javascript #es6
Refactoring Step 1: Eliminate the code `.then(response => response.data)` in each function by extracting this to a function called `getResponseData`.
#javascript #es6
Refactoring Step 2: Eliminate the URLs from each function by extracting this to a function called `createUrl`. The function will create a url based off the category and id.
#javascript #es6
Refactoring Step 3: Eliminate the code `getResponseData(createUrl(` from each function by extracting this into a function called `getData`. If we are always calling these two functions together, then it makes sense to compose these into a function.
#javascript #es6
Refactoring Step 4: Convert `getData` into a curried function. This will let us use Partial Application to apply the category argument. You can also use `bind` like `getData.bind(null, 'people')` to partially apply a non-curried function. I prefer curried syntax.
#javascript #es6
Refactoring (Optional) Step: Curry `createUrl` and convert `getData` to use Ramda's `pipe`. This is optional, as it doesn't add as much value compared to the other steps. I would only do this if the the entire app was written in this style.
#javascript #es6
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to JavaScript Joel 🍻
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!