UNPKG

@adyen/kyc-components

Version:

This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.

55 lines (54 loc) 2.11 kB
try { let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack; n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "a93b9233-73d8-4ca5-9ce0-26c5cc174ae2", e._sentryDebugIdIdentifier = "sentry-dbid-a93b9233-73d8-4ca5-9ce0-26c5cc174ae2"); } catch (e) {} import { useCallback, useEffect, useRef } from "preact/hooks"; //#region src/utils/debounce.ts /** * Returns a function that will only execute after no further calls have been made for a given time. * * **Note: functions returned by this are not suitable for use in components! For that, see {@link useDebouncedCallback}**. * * @param func the function to execute * @param wait the time to wait, in milliseconds */ var debounce = (func, wait) => { let timerId; let shouldInvoke; return (...args) => { shouldInvoke = true; if (!timerId) { func(...args); shouldInvoke = false; } clearTimeout(timerId); timerId = setTimeout(() => shouldInvoke && func(...args), wait); }; }; /** * Returns a memoized function that will only execute after no further calls have been made for a given time. * * Callbacks returned by this method *are* safe to use within components, as their reference will be guaranteed stable. * * @param func the function to execute * @param wait the time to wait, in milliseconds */ var useDebouncedCallback = (func, wait) => { const timeoutRef = useRef(); useEffect(() => { return () => clearTimeout(timeoutRef.current); }, []); return useCallback((...args) => { const later = () => { clearTimeout(timeoutRef.current); func(...args); }; clearTimeout(timeoutRef.current); timeoutRef.current = setTimeout(later, wait); }, [func, wait]); }; //#endregion //#region src/utils/analytics/debouncedInputEvent.ts var debouncedInputEvent = debounce((userEvents, properties) => userEvents.addFieldEvent("Interacted with form field", properties), 500); //#endregion export { debounce as n, useDebouncedCallback as r, debouncedInputEvent as t };