/** * @module Watch */ import { Controller, ControllerConfig } from "./controller"; import { Config } from "./index"; import { ObserverConfig } from "@ideal-postcodes/jsutil"; interface OnBindOptions extends ControllerConfig { } interface OnBindAttempt { (options: OnBindOptions): void; } interface OnAnchorFoundOptions { anchor: HTMLElement; scope: HTMLElement | Document | null; config: ControllerConfig; } interface OnAnchorFound { (options: OnAnchorFoundOptions): void; } export interface WatchOptions { /** * A function executed on every interval to determine whether binding should take place * * @default `() => true` */ pageTest?: () => boolean; /** * Callback executed when an AddressFinder instance successfully binds * * @default `NOOP` */ onBind?: (c: Controller) => void; /** * Error callback. Executes when general error will be thrown. */ onError?: (error: unknown) => void; /** * Callback executed each time bind is attempted * * @default `NOOP` */ onBindAttempt?: OnBindAttempt; /** * Callback executed when anchor and its scope is detected * * @default `NOOP` */ onAnchorFound?: OnAnchorFound; /** * Custom anchor. Set this if you do not wish to anchor the `watch` method using inputField or outputFields.line_1 * * @default `undefined` */ anchor?: string; /** * Sets the scope in which the AddressFinder can operate. Set to `null` to mark the whole page as in scope * * A function which provides the anchor as the first argument. The operable scope must be returned. By default the parent `