From f219d7bb492267c1fcbaebcc3e183358b4727775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=8D=A3?= <38655613+murongg@users.noreply.github.com> Date: Thu, 7 Jul 2022 07:01:43 +0000 Subject: [PATCH] feat(question): add #345 - useDebounce --- questions/345-usedebounce/README.md | 33 +++++++++++++++++++++++ questions/345-usedebounce/README.zh-CN.md | 33 +++++++++++++++++++++++ questions/345-usedebounce/info.yml | 7 +++++ questions/345-usedebounce/info.zh-CN.yml | 7 +++++ questions/345-usedebounce/useDebounce.ts | 21 +++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 questions/345-usedebounce/README.md create mode 100644 questions/345-usedebounce/README.zh-CN.md create mode 100644 questions/345-usedebounce/info.yml create mode 100644 questions/345-usedebounce/info.zh-CN.yml create mode 100644 questions/345-usedebounce/useDebounce.ts diff --git a/questions/345-usedebounce/README.md b/questions/345-usedebounce/README.md new file mode 100644 index 0000000..c74df77 --- /dev/null +++ b/questions/345-usedebounce/README.md @@ -0,0 +1,33 @@ + + + + +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 | Ref +type UseDebounce = any>(fn: T, wait: MaybeRef, 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... +} +``` + + + + diff --git a/questions/345-usedebounce/README.zh-CN.md b/questions/345-usedebounce/README.zh-CN.md new file mode 100644 index 0000000..ad412b0 --- /dev/null +++ b/questions/345-usedebounce/README.zh-CN.md @@ -0,0 +1,33 @@ + + + + +For this challenge, you need implement a debounce Composable Function.对于此挑战,您需要实现可访问的可组合功能。 Let's go.我们走吧。 + +``TS +导入类型{ref}从'vue' + +接口使用ebounceOptions { +领导?:布尔值//指定在超时的前沿调用。 +MaxWait?:NUMBER //允许弹药延迟的最大时间在调用之前被延迟。 +尾随?:布尔值//指定在超时的后缘上调用。 +} + +type MaybeRef类型Mayberef = T | = t | Ref参考 +type UseDebounce =类型使用的bounce = any>(fn: T, wait: MaybeRef任何>(fn:t,等等:Mayberef , options?: UseDebounceOptions) => T ,选项?:使用了ebouncoptions)=> t + +/** +*使用 +* @param fn要调试的功能。 +* @Param等待毫秒延迟的毫秒数。 +* @param选项选项对象。 +* @return返回新的拒绝功能。 +*/ +const usedebounce:undereebounce =(fn,wait,options)=> { +//做一些... +} +```````` + + + + diff --git a/questions/345-usedebounce/info.yml b/questions/345-usedebounce/info.yml new file mode 100644 index 0000000..6b3853c --- /dev/null +++ b/questions/345-usedebounce/info.yml @@ -0,0 +1,7 @@ +difficulty: hard +title: useDebounce +tags: Composable Function +author: + github: murongg + name: 木荣 + diff --git a/questions/345-usedebounce/info.zh-CN.yml b/questions/345-usedebounce/info.zh-CN.yml new file mode 100644 index 0000000..1f93658 --- /dev/null +++ b/questions/345-usedebounce/info.zh-CN.yml @@ -0,0 +1,7 @@ +difficulty: hard +title: 用过 +tags: Composable Function +author: + github: murongg + name: 木荣 + diff --git a/questions/345-usedebounce/useDebounce.ts b/questions/345-usedebounce/useDebounce.ts new file mode 100644 index 0000000..d1ddf89 --- /dev/null +++ b/questions/345-usedebounce/useDebounce.ts @@ -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 | Ref +type UseDebounce = any>(fn: T, wait: MaybeRef, 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... +} \ No newline at end of file