Skip to content

Instantly share code, notes, and snippets.

@marcossevilla
Created May 12, 2021 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcossevilla/381be3ee189c791736bfffbcd42281da to your computer and use it in GitHub Desktop.
Save marcossevilla/381be3ee189c791736bfffbcd42281da to your computer and use it in GitHub Desktop.
class SomeRepository implements ISomeRepository {
SomeRepository({
required ILocalDataSource localDataSource,
required IRemoteDataSource remoteDataSource,
}) : _localDataSource = localDataSource,
_remoteDataSource = remoteDataSource;
final ILocalDataSource _localDataSource;
final IRemoteDataSource _remoteDataSource;
@override
Future<SomeModel> getModel(int modelId) async {
try {
final model = await _remoteDataSource.getModel(modelId);
await _localDataSource.saveModel(model);
return model;
} catch (e) {
// si el llamado al API falla...
try {
final model = _localDataSource.getSavedModel();
return model;
} catch (e) {
throw CacheError();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment