startAsyncAF method
void
startAsyncAF(
- AFDispatcher dispatcher,
- AFStore store, {
- required Completer<
AFFinishQuerySuccessContext> ? completer, - void onResponseExtra(
- dynamic
- void onErrorExtra(
- dynamic
Called internally when redux middleware begins processing a query.
Implementation
void startAsyncAF(AFDispatcher dispatcher, AFStore store, {
required Completer<AFFinishQuerySuccessContext>? completer,
void Function(dynamic)? onResponseExtra,
void Function(dynamic)? onErrorExtra
}) {
lastStart = currentMillis();
final startContext = AFStartQueryContext<TResponse>(
conceptualStore: conceptualStore,
onSuccess: (response) {
// note: there could be multiple queries outstanding at once, meaning the state
// might be changed by some other query while we are waiting for a responser.
// Consequently, it is important not to make a copy of the state above this point,
// as it might go out of date.
final successContext = AFFinishQuerySuccessContext<TResponse>(
conceptualStore: conceptualStore,
response: response,
isPreExecute: false,
);
finishAsyncWithResponseAF(successContext);
if(onResponseExtra != null) {
onResponseExtra(successContext);
}
if(completer != null) {
completer.complete(successContext);
}
},
onError: (error) {
final errorContext = AFFinishQueryErrorContext(
conceptualStore: conceptualStore,
error: error
);
finishAsyncWithErrorAF(errorContext);
if(onErrorExtra != null) {
onErrorExtra(errorContext);
}
if(completer != null) {
completer.completeError(errorContext);
}
})
;
final pre = onPreExecuteResponse;
if(pre != null) {
final preResponse = pre();
final successContext = AFFinishQuerySuccessContext<TResponse>(
conceptualStore: conceptualStore,
response: preResponse,
isPreExecute: true,
);
finishAsyncWithResponseAF(successContext);
}
AFibD.logQueryAF?.d("Starting query: $this");
try {
startAsync(startContext);
} on AFFinishQueryErrorContext catch(errCtx) {
finishAsyncWithErrorAF(errCtx);
}
}