UNPKG

@shopify/cli-kit

Version:

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

56 lines 2.98 kB
import lodashMemoize from 'lodash/memoize.js'; import lodashDebounce from 'lodash/debounce.js'; import lodashThrottle from 'lodash/throttle.js'; /** * 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. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function memoize(func, resolver) { return lodashMemoize(func, resolver); } /** * 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. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function debounce(func, wait, options) { return lodashDebounce(func, wait, options); } /** * 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. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function throttle(func, wait, options) { return lodashThrottle(func, wait, options); } //# sourceMappingURL=function.js.map