UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

45 lines (44 loc) 2.81 kB
import type { DebouncedFunc, DebounceSettings, ThrottleSettings } from 'lodash'; /** * Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for * storing the result based on the arguments provided to the memoized function. By default, the first argument * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with * the this binding of the memoized function. * * @param func - The function to have its output memoized. * @param resolver - The function to resolve the cache key. * @returns Returns the new memoizing function. */ export declare function memoize<T extends (...args: any) => any>(func: T, resolver?: (...args: Parameters<T>) => unknown): T; /** * Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since * the last time the debounced function was invoked. The debounced function comes with a cancel method to * cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to * indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent * calls to the debounced function return the result of the last func invocation. * * Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only * if the the debounced function is invoked more than once during the wait timeout. * * See David Corbacho's article for details over the differences between _.debounce and _.throttle. * * @param func - The function to debounce. * @param wait - The number of milliseconds to delay. * @param options - The options object. * @returns Returns the new debounced function. */ export declare function debounce<T extends (...args: any) => any>(func: T, wait?: number, options?: DebounceSettings): DebouncedFunc<T>; /** * Creates a throttled function that only invokes func at most once per every wait milliseconds. * The throttled function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. * Provide an options object to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. * Subsequent calls to the throttled function return the result of the last func invocation. * * See David Corbacho's article for details over the differences between _.debounce and _.throttle. * * @param func - The function to throttle. * @param wait - The number of milliseconds to throttle invocations to. * @param options - The options object. * @returns Returns the new throttled function. */ export declare function throttle<T extends (...args: any) => any>(func: T, wait?: number, options?: ThrottleSettings): DebouncedFunc<T>;