handleMutations function
Last updated: 2026-03-04T23:21:38.393Z
Location
Metrics
LOC: 65
Complexity: 24
Params: 1
Signature
handleMutations(mutations: MutationRecord[]): : void
Architecture violations
- [warning] max-cyclomatic-complexity: 'handleMutations' has cyclomatic complexity 24 (max 10)
Source Code
function handleMutations(mutations: MutationRecord[]): void {
if (isFillingInProgress) return;
const isRelevant = mutations.some((m) => {
if (
m.type === "childList" &&
(m.addedNodes.length > 0 || m.removedNodes.length > 0)
) {
// When Shadow DOM is enabled, watch newly attached shadow hosts
if (activeConfig.shadowDOM) {
for (const node of m.addedNodes) {
if (node instanceof HTMLElement && node.shadowRoot) {
observeSingleShadowRoot(node.shadowRoot);
}
}
}
return true;
}
if (m.type === "attributes") {
const target = m.target as HTMLElement;
if (target.id === "fill-all-notification") return false;
if (
m.attributeName === "disabled" ||
m.attributeName === "hidden" ||
m.attributeName === "style" ||
m.attributeName === "class"
) {
return hasFormContent(target);
}
}
return false;
});
if (!isRelevant) return;
if (debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(async () => {
const newSignature = getCurrentFieldSignature();
if (newSignature !== lastFieldSignature) {
const previousSignature = lastFieldSignature;
const oldCount = previousSignature.split("|").filter(Boolean).length;
const newCount = newSignature.split("|").filter(Boolean).length;
const diff = newCount - oldCount;
lastFieldSignature = newSignature;
if (diff > 0) {
log.info(`Detected ${diff} new form field(s)`);
if (onNewFieldsCallback) {
onNewFieldsCallback(diff);
}
if (activeConfig.autoRefill) {
await refillNewFields(previousSignature);
}
} else if (diff !== 0) {
log.info(`Form structure changed (${diff} fields)`);
if (onNewFieldsCallback) {
onNewFieldsCallback(diff);
}
}
}
}, activeConfig.debounceMs);
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| observeSingleShadowRoot | calls |
| hasFormContent | calls |
| getCurrentFieldSignature | calls |
| refillNewFields | calls |
No incoming dependencies.