Skip to content

useDebounce #345

Open
Open
@murongg

Description

@murongg

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions