dynamic-forms / Function

applyMetaToElement

Applies meta attributes to a DOM element and tracks which attributes were applied.

This utility handles:

  • Removing previously applied attributes that are no longer in meta
  • Setting new attributes from meta
  • Converting all values to strings via String()

Presentation

function applyMetaToElement(
  element: Element,
  meta: FieldMeta | undefined,
  previouslyApplied: Set<string>,
): Set<string>;

Returns

Set<string> -

A new Set containing the attribute names that were applied

Parameters

NameTypeDescription
element
Element

The DOM element to apply attributes to

meta
FieldMeta | undefined

The meta object containing attributes to apply

previouslyApplied
Set<string>

Set of attribute names that were previously applied

Example usage

private appliedAttrs = new Set<string>();

explicitEffect([this.meta], ([meta]) => {
  const input = this.el.nativeElement.querySelector('input');
  if (input) {
    this.appliedAttrs = applyMetaToElement(input, meta, this.appliedAttrs);
  }
});