-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding guard * Adding tests * better guard * running build * running prettier * add docs * version bump
- Loading branch information
1 parent
31c1397
commit 77cb220
Showing
8 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: guard | ||
group: 'Async' | ||
description: Have a function return undefined if it errors out | ||
--- | ||
|
||
## Basic usage | ||
|
||
This lets you set a default value if an async function errors out. | ||
|
||
```ts | ||
const users = (await guard(fetchUsers)) ?? [] | ||
``` | ||
|
||
You can choose to guard only specific errors too | ||
|
||
```ts | ||
const isInvalidUserError = (err: any) => err.code === 'INVALID_ID' | ||
const user = (await guard(fetchUser, isInvalidUserError)) ?? DEFAULT_USER | ||
``` |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ export { | |
} from './array' | ||
export { | ||
defer, | ||
guard, | ||
map, | ||
parallel, | ||
reduce, | ||
|
This file contains 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
77cb220
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
radash-docs – ./
radash-docs.vercel.app
radash-docs-ray-unishinedev.vercel.app
radash-docs-git-master-ray-unishinedev.vercel.app