Skip to content

Commit

Permalink
feat(question): add #345 - useDebounce
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Jul 7, 2022
1 parent 5bffe68 commit e0f20f6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions questions/345-usedebounce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--info-header-start-->
<!--info-header-end-->


For this challenge, you need implement a debounce Composable Function. Let's go.


<!--info-footer-start-->
<!--info-footer-end-->
9 changes: 9 additions & 0 deletions questions/345-usedebounce/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--info-header-start-->
<!--info-header-end-->


<i>For this challenge, you need implement a debounce Composable Function.</i><b>对于此挑战,您需要实现可访问的可组合功能。</b> <i>Let&#39;s go.</i><b>我们走吧。</b>


<!--info-footer-start-->
<!--info-footer-end-->
7 changes: 7 additions & 0 deletions questions/345-usedebounce/info.yml
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: 木荣

7 changes: 7 additions & 0 deletions questions/345-usedebounce/info.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
difficulty: hard
title: 用过
tags: Composable Function
author:
github: murongg
name: 木荣

21 changes: 21 additions & 0 deletions questions/345-usedebounce/useDebounce.ts
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...
}

0 comments on commit e0f20f6

Please sign in to comment.