Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useDebounce #345

Open
murongg opened this issue Jul 7, 2022 · 1 comment · May be fixed by #347
Open

useDebounce #345

murongg opened this issue Jul 7, 2022 · 1 comment · May be fixed by #347

Comments

@murongg
Copy link
Contributor

murongg commented Jul 7, 2022

Info

Basic info of your challenge questions,

difficulty: hard
title: useDebounce
tags: Composable Function

Question

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

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...
}

Template

filename: useDebounce.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...
}
github-actions bot pushed a commit that referenced this issue Jul 7, 2022
@github-actions github-actions bot linked a pull request Jul 7, 2022 that will close this issue
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2022

#347 - Pull Request updated.

2022-07-07T07:01:43.933Z Preview in Playground

github-actions bot pushed a commit that referenced this issue Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant