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/modify-dom.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/shared/modify-dom.ts') diff --git a/src/shared/modify-dom.ts b/src/shared/modify-dom.ts index 22b8e8e..b268ae2 100644 --- a/src/shared/modify-dom.ts +++ b/src/shared/modify-dom.ts @@ -10,6 +10,11 @@ type DOMModificationRules = (DOMModificaitonRule | null)[]; let domModificationRules: DOMModificationRules = []; let domModificationFinishedCount = 0; +/** + * Runs whenever the DOM mutates. Iterates over pending modification + * rules; when the selector matches, the element's innerHTML and + * attributes are updated and the rule is marked as complete. + */ observeDOM(() => { for (let i = 0; i < domModificationRules.length; i++) { if (domModificationRules[i]) { @@ -45,6 +50,15 @@ observeDOM(() => { return false; }); +/** + * Registers one or more DOM modification rules. Each rule is a tuple of + * `[selector, attributeMap]`. When an element matching the selector is + * found, its `innerHTML` is replaced (if `attributeMap.innerHTML` is set) + * and all other entries in the map are applied as `setAttribute` calls + * (or `removeAttribute` when the value is `null`). + * + * @param modificationRules - Array of `[selector, attributes]` rules. + */ export function modifyDOM(modificationRules: DOMModificationRules) { domModificationRules = domModificationRules.concat(modificationRules); }; -- cgit v1.2.3