resolveActionAttribute method

void resolveActionAttribute(
  1. DOMTreeMap<T> treeMap,
  2. DOMElement domElement,
  3. T element,
  4. DOMContext<T>? context,
)

Implementation

void resolveActionAttribute(DOMTreeMap<T> treeMap, DOMElement domElement,
    T element, DOMContext<T>? context) {
  if (_domActionExecutor == null || domElement.tag == 'form') return;

  var actionValue = domElement.getAttributeValue('action', domContext);
  if (isEmptyString(actionValue)) return;

  var domAction = _domActionExecutor!.parse(actionValue);

  if (domAction != null) {
    EventStream<DOMEvent> eventStream = domElement.onClick;

    var tag = domElement.tag;
    if (tag == 'select' || tag == 'input' || tag == 'textarea') {
      eventStream = domElement.onChange;
    }

    eventStream.listen(
      (event) {
        var target = domElement.getRuntimeNode();
        var elementValue = getElementValue(element);

        var context2 = context?.copy() ?? DOMContext();

        var variables = context2.variables;
        variables['event'] = {
          'target': domElement,
          'value': elementValue,
          'event': '$event'
        };

        context2.variables = variables;

        domAction.execute(target, treeMap: treeMap, context: context2);
      },
      singletonIdentifier: domAction,
      singletonIdentifyByInstance: false,
      overwriteSingletonSubscription: true,
    );
  }
}