refillNewFields function

Last updated: 2026-03-04T23:21:38.393Z

Metrics

LOC: 38 Complexity: 4 Params: 1

Signature

refillNewFields(previousSignature: string): : Promise<void>

Summary

Re-fills only the new fields that appeared after a DOM change. Compares the previous signature against current fields to identify which fields are new and fills only those.

Source Code

async function refillNewFields(previousSignature: string): Promise<void> {
  isFillingInProgress = true;
  try {
    const oldKeys = parseSignature(previousSignature);
    const { fields } = await detectAllFieldsAsync();

    const newFields = fields.filter((f) => {
      const key = `${f.selector}:${f.fieldType}`;
      return !oldKeys.has(key);
    });

    if (newFields.length === 0) {
      log.debug("No truly new fields to fill");
      return;
    }

    const url = window.location.href;
    const ignoredFields = await getIgnoredFieldsForUrl(url);
    const ignoredSelectors = new Set(ignoredFields.map((f) => f.selector));
    const fieldsToFill = newFields.filter(
      (f) => !ignoredSelectors.has(f.selector),
    );

    if (fieldsToFill.length === 0) {
      log.debug("Todos os novos campos são ignorados — skip");
      return;
    }

    log.info(`Filling ${fieldsToFill.length} new field(s) only`);
    for (const field of fieldsToFill) {
      await fillSingleField(field);
    }

    lastFieldSignature = getCurrentFieldSignature();
  } finally {
    isFillingInProgress = false;
  }
}

Dependencies (Outgoing)

graph LR refillNewFields["refillNewFields"] parseSignature["parseSignature"] detectAllFieldsAsync["detectAllFieldsAsync"] fillSingleField["fillSingleField"] getCurrentFieldSignature["getCurrentFieldSignature"] refillNewFields -->|calls| parseSignature refillNewFields -->|calls| detectAllFieldsAsync refillNewFields -->|calls| fillSingleField refillNewFields -->|calls| getCurrentFieldSignature style refillNewFields fill:#dbeafe,stroke:#2563eb,stroke-width:2px click refillNewFields "07b7f93b13ced4af.html" click parseSignature "52c931d08cb489e0.html" click detectAllFieldsAsync "1b422b3353cdbe22.html" click fillSingleField "e1740bceca6b34c2.html" click getCurrentFieldSignature "e72508d8f19c287a.html"

Impact (Incoming)

graph LR refillNewFields["refillNewFields"] handleMutations["handleMutations"] handleMutations -->|calls| refillNewFields style refillNewFields fill:#dbeafe,stroke:#2563eb,stroke-width:2px click refillNewFields "07b7f93b13ced4af.html" click handleMutations "b707db53be39a752.html"
SourceType
handleMutations calls