UNPKG

@funnelenvy-npm/fe-dev-utils

Version:

Helper function to build client side A/B tests

19 lines (18 loc) 932 B
/** * Executes a callback function when the URL changes in a single page application (SPA). * Uses a MutationObserver to observe changes to the document body and detect URL changes. * @param {Object} options - Options object to configure the function. * @param {function} options.callback - The callback function to execute when the URL changes. * @param {string} [options.activity] - (Optional) Name of the activity the function is being called from. * @param {function} [options.errorHandler] - (Optional) Function to call when execution encounters an error. */ type OnUrlChangeOptions = { callback: (oldHref: string | undefined, mutation: MutationRecord) => void; activity?: string; errorHandler?: ((params: { activity?: string; error: Error; }) => void) | null; }; declare const onUrlChange: ({ callback, activity, errorHandler, }: OnUrlChangeOptions) => void; export default onUrlChange;