UNPKG

@ventum-digital/wait-on

Version:

Functions for waiting on DOM elements in SailPoint IdentityIQ

43 lines (42 loc) 3.06 kB
/** * Waits for a DOM element to appear in the document and executes a callback function when the element is found. * * @param {string} selector - The CSS selector of the element to wait for. * @param {function} callback - The function to be executed once the element is found. The found element is passed as an argument to this function. * @param {number} [timeout=1000] - The interval in milliseconds to wait before checking for the element again. * @param {?number} [maxTimeToWait=null] - The maximum time in milliseconds to wait for the element to appear. If this time passes without finding the element, the function stops checking. If null, there is no limit. */ export declare function waitOnElement(selector: string, callback: (element: Element) => void, timeout?: number, maxTimeToWait?: number | null): void; /** * Waits for a specific DOM element, identified by a CSS selector, to become null (i.e., removed from the DOM) * and invokes a callback function once the element is no longer present. The check is performed periodically * with a defined timeout interval. * * @param {string} selector - The CSS selector used to identify the element in the DOM. * @param {Function} callback - The function to be executed once the element becomes null or is removed from the DOM. * @param {number} [timeout=1000] - The interval duration, in milliseconds, after which the DOM is rechecked. Defaults to 1000 ms. */ export declare function waitOnElementToBeNull(selector: string, callback: () => void, timeout?: number): void; /** * Waits for a specified condition to be true before invoking a callback function. * * This function recursively checks the provided condition at regular intervals * and executes the callback when the condition returns true. A timeout period * defines the interval between condition checks. * * @param {Function} condition - A function returning a boolean value that determines if the wait should end. * @param {Function} callback - The function to execute once the condition evaluates to true. * @param {number} [timeout=1000] - The interval in milliseconds to wait between condition checks. */ export declare function waitOn(condition: () => boolean, callback: () => void, timeout?: number): void; export type AngularScope = any; /** * Retrieves the AngularJS scope associated with a given DOM element selected by a CSS selector and runs a callback function with the scope. * * @param {string} selector - The CSS selector used to identify the DOM element. * @param {(scope: AngularScope) => void} callback - A callback function that is executed once the AngularJS scope is retrieved. The scope is passed as an argument to the callback. * @return {void} This function does not return a value but executes a callback with the AngularJS scope as an argument. * * @throws {Error} Throws an error if the element with the specified selector is not found in the document. */ export declare function waitOnAngularCtrlScope(selector: string, callback: (scope: AngularScope) => void, timeout?: number): void;