From 600c337b1cdc884aebf59083eb57b178b43441ce Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 11:35:08 +0530 Subject: docs: added some documentation comments to all functions --- src/shared/observe-dom.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/shared/observe-dom.ts') diff --git a/src/shared/observe-dom.ts b/src/shared/observe-dom.ts index e82ce1e..90a52ff 100644 --- a/src/shared/observe-dom.ts +++ b/src/shared/observe-dom.ts @@ -3,6 +3,12 @@ type ObserveDOMCallback = () => boolean; let callbacks: (ObserveDOMCallback | null)[] = []; let callbacksCalledCount = 0; +/** + * Starts a MutationObserver on the document that invokes each + * registered callback. A callback should return `true` when it + * has completed its work; once all callbacks are done the observer + * disconnects. + */ const observer = new MutationObserver(() => { for (let i = 0; i < callbacks.length; i++) { const callback = callbacks[i]; @@ -24,6 +30,14 @@ observer.observe(document, { subtree: true }); +/** + * Registers a callback to run on DOM mutations. + * The callback is invoked on each mutation tick and should return `true` + * when its work is finished. When all callbacks have completed the + * observer stops. + * + * @param callback - Function that returns `true` when done. + */ export function observeDOM(callback: ObserveDOMCallback) { callbacks.push(callback); }; -- cgit v1.2.3