run method

  1. @nonVirtual
Future<void> run(
  1. BuildContext buildContext,
  2. NodeSpec action,
  3. Map state,
  4. Object? eventValue,
  5. Map? actionContext,
)

Starts the execution of an action

Implementation

@nonVirtual
Future<void> run(BuildContext buildContext, NodeSpec action, Map state,
    Object? eventValue, Map? actionContext) async {
  if (!await preRun(buildContext, action.props)) {
    return;
  }
  if (!buildContext.mounted) {
    log.severe("BuildContext is not mounted after preRun.");
    return;
  }

  final runState = actionContext ?? {};
  var currentValue = eventValue;
  NodeSpec? currentAction = action.clone();

  while (currentAction != null) {
    if (!buildContext.mounted) {
      log.severe(
          "BuildContext is not mounted while trying to execute Action '${currentAction.type}' (${currentAction.id})");
      return;
    }

    final context =
        ActionContext(state, runState, currentValue, buildContext);
    if (!await preExecute(currentAction, context)) {
      break;
    }

    final result = await execute(currentAction, context);
    currentAction = await postExecute(currentAction, result, context);
    currentValue = result.returnData;
  }
  onExecuted();
}