-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asyncNoop): add asyncNoop (#903)
* feat(asyncNoop): add asyncNoop * Update docs/ko/reference/function/asyncNoop.md * Update docs/ja/reference/function/asyncNoop.md * Update docs/reference/function/asyncNoop.md * Update docs/zh_hans/reference/function/asyncNoop.md --------- Co-authored-by: Sojin Park <[email protected]>
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# asyncNoop | ||
|
||
非同期で何もしない関数です。 関数を要求する場所に空白を埋めるために使用したり、デフォルトで使用することができます。 | ||
|
||
## インターフェース | ||
|
||
```typescript | ||
function asyncNoop(): Promise<void>; | ||
``` | ||
|
||
### 戻り値 | ||
|
||
(`Promise<void>`): `undefined` に解決する `Promise`。 | ||
|
||
## 例 | ||
|
||
```typescript | ||
import { asyncNoop } from 'es-toolkit/function'; | ||
|
||
interface Props { | ||
fetchData?: () => Promise<void>; | ||
} | ||
|
||
function MyComponent({ fetchData = asyncNoop }: Props) { | ||
const handleFetchData = async () => { | ||
// ここでfetchDataは関数であることが保証されているため、安全に呼び出すことができます。 | ||
await fetchData(); | ||
}; | ||
|
||
handleFetchData(); | ||
} | ||
``` |
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,32 @@ | ||
# asyncNoop | ||
|
||
비동기적으로 아무것도 하지 않는 함수예요. 함수를 요구하는 곳에 빈 자리를 채우기 위해 사용하거나, 기본값으로 사용할 수 있어요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function asyncNoop(): Promise<void>; | ||
``` | ||
|
||
### 반환 값 | ||
|
||
(`Promise<void>`): `undefined`로 이행하는 `Promise`. | ||
|
||
## 예시 | ||
|
||
```typescript | ||
import { asyncNoop } from 'es-toolkit/function'; | ||
|
||
interface Props { | ||
fetchData?: () => Promise<void>; | ||
} | ||
|
||
function MyComponent({ fetchData = asyncNoop }: Props) { | ||
const handleFetchData = async () => { | ||
// 여기서 fetchData는 undefined일 수 없어서, 자유롭게 부를 수 있어요. | ||
await fetchData(); | ||
}; | ||
|
||
handleFetchData(); | ||
} | ||
``` |
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,32 @@ | ||
# asyncNoop | ||
|
||
An asynchronous no-operation function that does nothing. This can be used as a placeholder or default function. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function asyncNoop(): Promise<void>; | ||
``` | ||
|
||
### Returns | ||
|
||
(`Promise<void>`): A Promise that resolves to undefined. | ||
|
||
## Examples | ||
|
||
```typescript | ||
import { asyncNoop } from 'es-toolkit/function'; | ||
|
||
interface Props { | ||
fetchData?: () => Promise<void>; | ||
} | ||
|
||
function MyComponent({ fetchData = asyncNoop }: Props) { | ||
const handleFetchData = async () => { | ||
// Here fetchData is guaranteed to be a function, so it's safe to call. | ||
await fetchData(); | ||
}; | ||
|
||
handleFetchData(); | ||
} | ||
``` |
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,32 @@ | ||
# asyncNoop | ||
|
||
一个非同步的空函数。 可以用来在函数需要的地方填充空白,或者作为默认值使用。 | ||
|
||
## 接口 | ||
|
||
```typescript | ||
function asyncNoop(): Promise<void>; | ||
``` | ||
|
||
### 返回值 | ||
|
||
(`Promise<void>`): 一个`Promise`,它将解析为`undefined`。 | ||
|
||
## 示例 | ||
|
||
```typescript | ||
import { asyncNoop } from 'es-toolkit/function'; | ||
|
||
interface Props { | ||
fetchData?: () => Promise<void>; | ||
} | ||
|
||
function MyComponent({ fetchData = asyncNoop }: Props) { | ||
const handleFetchData = async () => { | ||
// 这里fetchData是函数,所以可以安全地调用。 | ||
await fetchData(); | ||
}; | ||
|
||
handleFetchData(); | ||
} | ||
``` |
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,16 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { asyncNoop } from './asyncNoop'; | ||
|
||
describe('asyncNoop', () => { | ||
it('should be a function', () => { | ||
expect(typeof asyncNoop).toBe('function'); | ||
}); | ||
|
||
it('should return a Promise', () => { | ||
expect(asyncNoop()).toBeInstanceOf(Promise); | ||
}); | ||
|
||
it('should resolve to undefined', async () => { | ||
await expect(asyncNoop()).resolves.toBeUndefined(); | ||
}); | ||
}); |
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,10 @@ | ||
/** | ||
* An asynchronous no-operation function that does nothing. | ||
* This can be used as a placeholder or default function. | ||
* | ||
* @example | ||
* asyncNoop(); // Does nothing | ||
* | ||
* @returns {Promise<void>} This function returns a Promise that resolves to undefined. | ||
*/ | ||
export async function asyncNoop(): Promise<void> {} |
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