Skip to content

Commit 73bf607

Browse files
committed
chore: update hero
1 parent a431d70 commit 73bf607

File tree

1 file changed

+19
-8
lines changed
  • apps/documentation-website/src/components

1 file changed

+19
-8
lines changed

apps/documentation-website/src/components/Hero.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import blurIndigoImage from '@/images/blur-indigo.png'
1010

1111
const codeLanguage = 'typescript'
1212

13-
const code = `import { safe, createSafe } from '@cometloop/safe'
14-
import { fetchUserAsync, fetchPostsAsync } from '@features'
15-
import { errorParser, resultParser } from '@lib/utils'
16-
import { errorHook, successHook } from '@lib/hooks'
13+
const code = `// One-off wrapping — zero config
14+
const safeJSONParse = safe.wrap(JSON.parse)
15+
const [parsed, parseErr] = safeJSONParse(rawInput)
1716
18-
// One-off wrapping — zero config
1917
const fetchUserOnce = safe.wrapAsync(fetchUserAsync)
2018
const [basicUser, basicError] = await fetchUserOnce('admin-456')
2119
@@ -25,21 +23,34 @@ const apiSafe = createSafe({
2523
parseResult: resultParser,
2624
onError: errorHook,
2725
onSuccess: successHook,
26+
onSettled: settledHook,
2827
})
2928
3029
const fetchUser = apiSafe.wrapAsync(fetchUserAsync)
3130
const fetchPosts = apiSafe.wrapAsync(fetchPostsAsync)
3231
33-
// Same API. More power.
32+
// Same shared config. Full type narrowing.
3433
const [user, userError] = await fetchUser('123')
3534
if (userError) return
3635
3736
const [posts, postsError] = await fetchPosts(user.id)
3837
if (postsError) return
3938
40-
// Fully type-narrowed — never undefined
4139
console.log(user.name)
42-
console.log(posts.length)`
40+
console.log(posts.length)
41+
42+
// Add resilience — retry with backoff + auto-cancel
43+
const fetchUserRetry = apiSafe.wrapAsync(fetchUserAsync, {
44+
retry: { times: 3, waitBefore: (n) => n * 1000 },
45+
abortAfter: 5000,
46+
onRetry: (err, attempt) => console.log(\`Retry #\${attempt}...\`),
47+
})
48+
49+
// Prefer objects? One call to switch.
50+
const objSafe = withObjects(apiSafe)
51+
const fetchPostsObj = objSafe.wrapAsync(fetchPostsAsync)
52+
const { ok, data, error } = await fetchPostsObj('123')
53+
`
4354

4455
// const code = `import { safe } from '@cometloop/safe'
4556
// import { fetchUserAsync } from '@lib/api'

0 commit comments

Comments
 (0)