This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add --dev eslint-config-prettier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
... | |
extends: [ | |
'plugin:prettier/recommended', | |
], | |
rules: { | |
'prettier/prettier': 'error', | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @/__tests__/utils/getChartOptionsObj.spec.js | |
describe("@/utils/getChartOptionsObj", () => { | |
const chartData = [1, 2, 3] | |
const defaultChart = getDefaultChartObj({ chartData }) | |
it("passes along defaultChart only without extraOptions", () => { | |
const output = getChartOptionsObj({ chartData }) | |
expect(output).toBe(defaultChart) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @/utils/getChartOptionsObj.js | |
export default function getChartOptionsObj({ | |
chartData, | |
maximum, | |
limitOne, | |
limitTwo, | |
percent, | |
extraOptions, | |
}) { | |
const defaultChart = getDefaultChartObj({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @/__tests__/utils/getChartOptions.spec.js | |
describe("@/utils/getChartOptions", () => { | |
const chartData = [1, 2, 3] | |
const defaultChart = getDefaultChart(chartData) | |
it("passes along defaultChart only without extraOptions", () => { | |
const output = getChartOptions(chartData) | |
expect(output).toBe(defaultChart) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @/utils/getChartOptions.js | |
export default function getChartOptions( | |
chartData, | |
maximum, | |
limitOne, | |
limitTwo, | |
percent, | |
extraOptions | |
) { | |
const defaultChart = getDefaultChart( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We'll query the Rick and Morty API using a GET request: | |
const URL = "https://rickandmortyapi.com/api/character/" | |
const fetchCharacter = (id) => { | |
const httpRequest = new XMLHttpRequest() | |
httpRequest.open("GET", `${URL}${id}`) | |
httpRequest.send() | |
return httpRequest.responseText | |
} | |
const fetchJerry = () => fetchCharacter(5) // Jerry has id 5. | |
const result = fetchJerry() // The result is always undefined. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We'll query the Rick and Morty API using a GET request: | |
const URL = "https://rickandmortyapi.com/api/character/" | |
const fetchCharacter = (id) => { | |
const httpRequest = new XMLHttpRequest() | |
// When the request is loaded, call the callback function: | |
httpRequest.onload = function () { | |
callback(httpRequest.responseText) | |
} | |
httpRequest.open("GET", `${URL}${id}`) | |
httpRequest.send() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We'll query the Rick and Morty API using a GET request: | |
const URL = "https://rickandmortyapi.com/api/character/" | |
const fetchCharacter = async (id) => { | |
const response = await fetch(`${URL}${id}`) | |
return await response.json() | |
} | |
// Any function with an await keyword must be labeled async: | |
const fetchJerry = async () => await fetchCharacter(5) | |
const result = await fetchJerry() // We await the fetch call. | |
const { name, status } = result ? result : {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We'll query the Rick and Morty API using a GET request: | |
const URL = "https://rickandmortyapi.com/api/character/" | |
const fetchCharacter = (id) => { | |
return fetch(`${URL}${id}`).then((response) => response.json()) | |
} | |
const fetchJerry = () => fetchCharacter(5) | |
fetchJerry().then((result) => { | |
const { name, status } = result ? result : {} | |
console.log(`${name} is ${status}`) // Jerry Smith is Alive | |
}) |