style: format codebase

This commit is contained in:
Jean-Philippe Sirois
2020-05-19 21:57:49 -04:00
parent 0eaea34b28
commit a1283334b3
37 changed files with 146 additions and 138 deletions
@@ -130,13 +130,13 @@ Below is the same code implemented without using Async / Await as a comparision.
```js
function getCharacters() {
return fetch(`https://rickandmortyapi.com/api/character`)
.then(response => response.json())
.then(response => response.results);
.then((response) => response.json())
.then((response) => response.results);
}
getCharacters()
.then(characters => {
.then((characters) => {
console.log(characters); // (20) [{...}, {...}, {...}]
})
.catch(err => console.error(err));
.catch((err) => console.error(err));
```
@@ -43,7 +43,7 @@ In order to access this information, we'll have to call the `.then` method on ou
to access the actual members like so.
```js
getMembers("The Programmers Hangout").then(members => {
getMembers("The Programmers Hangout").then((members) => {
console.log(members); // (32k) [{...}, {...}, {...}]
});
```
@@ -64,7 +64,7 @@ You may have tried doing something like this before.
```js
// Incorrect code, don't copy!
let results;
getWeather("Los Angeles").then(weather => {
getWeather("Los Angeles").then((weather) => {
results = weather;
});
console.log(results); // undefined
@@ -80,7 +80,7 @@ you can watch [this amazing talk](https://youtu.be/8aGhZQkoFbQ) on it to learn m
In order to fix this problem we need to move the `console.log` inside the `.then` callback like so:
```js
getWeather("Los Angeles").then(weather => {
getWeather("Los Angeles").then((weather) => {
console.log(weather); // Sunny, probably
});
```
@@ -93,11 +93,11 @@ You can try it in your browser if you want to test it out.
```js
function getCharacters() {
return fetch(`https://rickandmortyapi.com/api/character`)
.then(response => response.json())
.then(response => response.results);
.then((response) => response.json())
.then((response) => response.results);
}
getCharacters().then(characters => {
getCharacters().then((characters) => {
console.log(characters); // (20) [{...}, {...}, {...}]
});
```
@@ -9,9 +9,9 @@ The first naive attempt, using new Promise for something that already returns a
```js
function doAsync(number) {
return new Promise(function(resolve, reject) {
doDatabase().then(function(dbResult) {
otherDbFunction(dbResult).then(function(secondResult) {
return new Promise(function (resolve, reject) {
doDatabase().then(function (dbResult) {
otherDbFunction(dbResult).then(function (secondResult) {
resolve(secondResult + 10);
});
});
@@ -24,8 +24,8 @@ already returns a promise, you can just return the original thing.
```js
function doAsync(number) {
return doDatabase().then(function(dbResult) {
otherDbFunction(dbResult).then(function(secondResult) {
return doDatabase().then(function (dbResult) {
otherDbFunction(dbResult).then(function (secondResult) {
return secondResult + 10;
});
});
@@ -38,10 +38,10 @@ is that they allow you to chain them sequentially.
```js
function doAsync(number) {
return doDatabase()
.then(function(dbResult) {
.then(function (dbResult) {
return otherDbFunction(dbResult);
})
.then(function(secondResult) {
.then(function (secondResult) {
return secondResult + 10;
});
}
@@ -54,7 +54,7 @@ variable, you can pass in the entire function itself to the then block
function doAsync(number) {
return doDatabase()
.then(otherDbFunction)
.then(function(secondResult) {
.then(function (secondResult) {
return secondResult + 10;
});
}
@@ -63,10 +63,10 @@ function doAsync(number) {
And you don't need those returns if you just have ES6 arrow functions
```js
const doAsync = number =>
const doAsync = (number) =>
doDatabase()
.then(otherDbFunction)
.then(secondResult => secondResult + 10);
.then((secondResult) => secondResult + 10);
```
Wow, that last one looks a lot cleaner to me than the first. Keeping that in mind, maybe we could be making some of our other functions cleaner as well