Skip to content

Commit cb8b8a4

Browse files
feat(website): update getting started docs (#52)
1 parent 95592bc commit cb8b8a4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

website/docs/getting-started.mdx

+9-10
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,19 @@ import {
134134
} from 'lfi'
135135

136136
// The file has one sloth name per line
137-
const filename = `every-sloth-name.txt`
137+
const FILENAME = `every-sloth-name.txt`
138+
const API_URL = `https://random-word-form.herokuapp.com/random/adjective`
138139

139140
const slothSquadStatementsPromise = pipe(
140141
// Create an async iterable over the file lines, in this case sloth names
141-
(await fetch(new URL(`https://lfi.dev/${filename}`))).body,
142+
(await fetch(new URL(`https://lfi.dev/${FILENAME}`))).body,
142143
flatMapAsync(chunk => new TextDecoder().decode(chunk).split(`\n`)),
143144
// Chunk the sloth names into array groups of 4, also known as a sloth squad
144145
chunkAsync(4),
145146
// Transform each sloth squad into a statement by asynchronously querying an
146147
// API for an adjective to describe the squad
147148
mapAsync(async slothSquad => {
148-
const [adjective] = await (
149-
await fetch(`https://random-word-form.herokuapp.com/random/adjective`)
150-
).json()
149+
const [adjective] = await (await fetch(API_URL)).json()
151150
const leadingSloths = slothSquad.slice(0, 3)
152151
const trailingSloth = slothSquad.at(-1)
153152
return `${leadingSloths.join(`, `)}, and ${trailingSloth} are ${adjective}!`
@@ -195,11 +194,12 @@ import {
195194
} from 'lfi'
196195

197196
// The file has one sloth name per line
198-
const filename = `every-sloth-name.txt`
197+
const FILENAME = `every-sloth-name.txt`
198+
const API_URL = `https://random-word-form.herokuapp.com/random/adjective`
199199

200200
const slothSquadStatementsPromise = pipe(
201201
// Create an async iterable over the file lines, in this case sloth names
202-
(await fetch(new URL(`https://lfi.dev/${filename}`))).body,
202+
(await fetch(new URL(`https://lfi.dev/${FILENAME}`))).body,
203203
flatMapAsync(chunk => new TextDecoder().decode(chunk).split(`\n`)),
204204
// Chunk the sloth names into array groups of 4, also known as a sloth squad
205205
chunkAsync(4),
@@ -211,9 +211,7 @@ const slothSquadStatementsPromise = pipe(
211211
// API for an adjective to describe the squad, all concurrently with other
212212
// squads
213213
mapConcur(async slothSquad => {
214-
const [adjective] = await (
215-
await fetch(`https://random-word-form.herokuapp.com/random/adjective`)
216-
).json()
214+
const [adjective] = await (await fetch(API_URL)).json()
217215
const leadingSloths = slothSquad.slice(0, 3)
218216
const trailingSloth = slothSquad.at(-1)
219217
return `${leadingSloths.join(`, `)}, and ${trailingSloth} are ${adjective}`
@@ -225,6 +223,7 @@ const slothSquadStatementsPromise = pipe(
225223
)
226224

227225
console.log(await slothSquadStatementsPromise)
226+
// NOTE: This order may change between runs
228227
//=> [
229228
//=> 'strawberry, max, bitsy, and tommy jolly!',
230229
//=> 'ava, brooke, lottie, and jeremiah are beloved!',

0 commit comments

Comments
 (0)