loadResource method
Loads a resource from cache -> storage -> REST API. User can opt in to stopOnFirstResourceLoaded, which means when a resource is completed loaded (dataLoaded != null) then no further load will be made
Implementation
Future<Resource<DataType?>> loadResource() async {
Resource<DataType?> resource =
Resource<DataType?>(status: ResourceStatus.TRANSIENT);
try {
if (loadFromCache != null) resource = await handleLoadFromCache();
if (hasResourceCompletedLoading(resource)) return resource;
if (loadFromStorage != null) resource = await handleLoadFromStorage();
if (hasResourceCompletedLoading(resource)) return resource;
if (loadFromRESTAPI != null) resource = await handleLoadFromRESTAPI();
if (!hasResourceCompletedLoading(resource)) {
resource.status = ResourceStatus.SUCCESS;
if (publishResults) publishSubject?.post(resource);
}
} catch (e) {
resource = await handleOnFailed(e);
}
return resource;
}