attributeSignal method

Signal<String?> attributeSignal(
  1. String name
)

Returns a reactive Signal tracking the value of attribute name.

Automatically updates whenever attributeChangedCallback fires on the custom element. Reading this signal inside a Live or effect creates a reactive dependency on the DOM attribute.

final variant = context.attributeSignal('variant');

Implementation

Signal<String?> attributeSignal(String name) {
  return _attrSignals.putIfAbsent(
    name,
    () => signal(host.getAttribute(name)),
  );
}