export interface Watcher { elementConnected?: (element: T) => void; elementDisconnected?: (element: T) => void; /** * Only fires for elements still in the document when the mutation record is delivered. An element mutated and then * removed in the same task gets a single `elementDisconnected` instead. * * Fires for every attribute change the shared observer delivers. That always includes the attributes this watcher's * selector depends on, but may include attributes only other watchers depend on (every attribute, while any * registered selector is not read as self-contained), so check `attributeName`. */ elementAttributeChanged?: (element: T, attributeName: string) => void; } /** * Registers a watcher for elements matching `selector`. The shared document-level MutationObserver is started on first * registration and torn down once the last watcher is removed. A callback that throws is reported like an uncaught * error and never unwinds the observer or this function, so other watchers and later mutation records still run. * * Nothing is matched before the document is Parsed (docs/adr/0003). A watcher registered while `readyState` is * `loading` joins the index on `DOMContentLoaded`. One registered later scans the document before this function * returns, which the token routers rely on to replay tokens already on the page. Records still queued are delivered * first, to every watcher, unless it is registered from a callback run during a delivery (see `startDelivery`). * * Returns a cleanup function that deregisters the watcher and forgets every element it had matched. It does not fire * `elementDisconnected` for them; callers that need teardown must handle it themselves. * * Throws for a selector {@link assertValidSelector} rejects, whether or not the document is Parsed, before anything is * registered: every watcher's selector is queried in one list, so one that is invalid there fails for all of them. */ export declare function watchSelector(selector: string, watcher: Watcher): () => void; /** * Delivers every mutation record the shared observer has queued but not yet dispatched, so callers that need the index * to reflect the DOM as of now (rather than as of the last microtask checkpoint) can read it synchronously. That * includes the records the callbacks queue while it runs. */ export declare function flushMutations(): void; /** * Whether the DOM has changes the watchers have not been handed yet. Returns `0` when there are none, or while a * delivery is running (a callback reads what has been delivered so far). Otherwise returns a number that goes up * whenever more changes are waiting, so a caller can reuse what it worked out from the DOM until then. * * Asking delivers nothing and moves nothing. The observer's records are the only way to see the changes, so they are * taken and held, and the nudge leaves a record behind: the observer's callback comes when it would have, and the held * records are delivered first in its batch. */ export declare function undeliveredVersion(): number; /** * The number of the delivery that is running, a nested one being part of the one it runs in, or `0` when none is. Two * calls return the same number only within one delivery. */ export declare function currentDelivery(): number; /** * Starts a delivery, which hands changes to callbacks: a batch of records, a new watcher's first scan, or a token * router's replay or teardown. Until {@link endDelivery} is called with what this returns, from a `finally`, * {@link undeliveredVersion} reports nothing waiting, so a callback reads what has been delivered so far, and a newly * registered watcher leaves queued records alone. Records have to be delivered in order, and a delivery walks a list it * took before its first callback: records delivered from a callback could drop an element the walk then connects * anyway, detached and never to be disconnected. * * A pair of calls rather than a function taking a callback: the batch loop and the routers' replay and teardown are * hot, and running them in a closure cost `attributes-fallback` about 9% and `body-swap` about 4%. */ export declare function startDelivery(): boolean; /** Ends the delivery {@link startDelivery} started; `nested` is what that returned. */ export declare function endDelivery(nested: boolean): void; /** {@link startDelivery} and {@link endDelivery} around `deliver`, where a closure costs nothing that matters. */ export declare function whileDelivering(deliver: () => void): void; //# sourceMappingURL=document_observer.d.ts.map