dispatch method

  1. @override
dynamic dispatch(
  1. dynamic action
)
override

Implementation

@override
dynamic dispatch(dynamic action) {

  if(action is AFExecuteBeforeInterface) {
    final queryBefore = action.executeBefore;

    if(queryBefore != null) {
      // create a composite query to execute the original query.
      final composite = AFCompositeQuery.createFrom(queries: [queryBefore], onSuccess: (compositeSuccess) {
        // execute the original action after it finishes successfully, note that currently on error, we just drop
        // the original action.   I think that is fairly reasonable, as it is likely that an error will have been displayed
        // to the user, which implicitly explains why the action didn't have the intended effect.
        store.dispatch(action);
      });

      // execute the composite.
      store.dispatch(composite);
      return;
    }
  }

  if(action is AFExecuteDuringInterface) {
    // in this case, we don't wait for the query to finish, we just execute the query, and fall through to immediately execute the action.
    final query = action.executeDuring;

    if(query != null) {
      store.dispatch(query);

    }
  }


  if(AFibD.config.requiresTestData && !isTestAction(action) && action is AFActionWithKey) {
    AFibF.g.testOnlyRegisterRegisterAction(action);
    AFibD.logTestAF?.d("Registered action: $action");
  }



  return store.dispatch(action);
}