-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(question): add #345 - useDebounce
- Loading branch information
Showing
5 changed files
with
101 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,33 @@ | ||
<!--info-header-start--> | ||
<!--info-header-end--> | ||
|
||
|
||
For this challenge, you need implement a debounce Composable Function. Let's go. | ||
|
||
```ts | ||
import type { Ref} from 'vue' | ||
|
||
interface UseDebounceOptions { | ||
leading?: boolean // Specify invoking on the leading edge of the timeout. | ||
maxWait?: number // The maximum time func is allowed to be delayed before it's invoked. | ||
trailing?: boolean // Specify invoking on the trailing edge of the timeout. | ||
} | ||
|
||
type MaybeRef<T> = T | Ref<T> | ||
type UseDebounce = <T extends (...args: any[]) => any>(fn: T, wait: MaybeRef<number>, options?: UseDebounceOptions) => T | ||
|
||
/** | ||
* useDebounce | ||
* @param fn The function to debounce. | ||
* @param wait The number of milliseconds to delay. | ||
* @param options The options object. | ||
* @return Returns the new debounced function. | ||
*/ | ||
const useDebounce: UseDebounce = (fn, wait, options) => { | ||
// do someting... | ||
} | ||
``` | ||
|
||
|
||
<!--info-footer-start--> | ||
<!--info-footer-end--> |
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,33 @@ | ||
<!--info-header-start--> | ||
<!--info-header-end--> | ||
|
||
|
||
<i>For this challenge, you need implement a debounce Composable Function.</i><b>对于此挑战,您需要实现可访问的可组合功能。</b> <i>Let's go.</i><b>我们走吧。</b> | ||
|
||
``TS | ||
导入类型{ref}从'vue' | ||
|
||
接口使用ebounceOptions { | ||
领导?:布尔值//指定在超时的前沿调用。 | ||
MaxWait?:NUMBER //允许弹药延迟的最大时间在调用之前被延迟。 | ||
尾随?:布尔值//指定在超时的后缘上调用。 | ||
} | ||
|
||
<i>type MaybeRef</i><b>类型Mayberef</b><T> <i>= T |</i> <b>= t |</b> <i>Ref</i><b>参考</b><T> | ||
<i>type UseDebounce =</i><b>类型使用的bounce =</b><T extends (...args: any[]) => <i>any>(fn: T, wait: MaybeRef</i><b>任何>(fn:t,等等:Mayberef</b><number> <i>, options?: UseDebounceOptions) => T</i> <b>,选项?:使用了ebouncoptions)=> t</b> | ||
|
||
/** | ||
*使用 | ||
* @param fn要调试的功能。 | ||
* @Param等待毫秒延迟的毫秒数。 | ||
* @param选项选项对象。 | ||
* @return返回新的拒绝功能。 | ||
*/ | ||
const usedebounce:undereebounce =(fn,wait,options)=> { | ||
//做一些... | ||
} | ||
```````` | ||
<!--info-footer-start--> | ||
<!--info-footer-end--> |
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,7 @@ | ||
difficulty: hard | ||
title: useDebounce | ||
tags: Composable Function | ||
author: | ||
github: murongg | ||
name: 木荣 | ||
|
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,7 @@ | ||
difficulty: hard | ||
title: 用过 | ||
tags: Composable Function | ||
author: | ||
github: murongg | ||
name: 木荣 | ||
|
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,21 @@ | ||
import type { Ref} from 'vue' | ||
|
||
interface UseDebounceOptions { | ||
leading?: boolean // Specify invoking on the leading edge of the timeout. | ||
maxWait?: number // The maximum time func is allowed to be delayed before it's invoked. | ||
trailing?: boolean // Specify invoking on the trailing edge of the timeout. | ||
} | ||
|
||
type MaybeRef<T> = T | Ref<T> | ||
type UseDebounce = <T extends (...args: any[]) => any>(fn: T, wait: MaybeRef<number>, options?: UseDebounceOptions) => T | ||
|
||
/** | ||
* useDebounce | ||
* @param fn The function to debounce. | ||
* @param wait The number of milliseconds to delay. | ||
* @param options The options object. | ||
* @return Returns the new debounced function. | ||
*/ | ||
const useDebounce: UseDebounce = (fn, wait, options) => { | ||
// do someting... | ||
} |