Add Wyatt Continuous Deployment as Sub package #236
| @ -50,10 +50,10 @@ class Photo extends Entity { | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| Then create the data sources by extending `BaseLocalDataSource` or `BaseRemoteDataSource` depending the type of data source. | ||||
| Then create the data sources by extending `BaseDataSource` : | ||||
| 
 | ||||
| ```dart | ||||
| abstract class PhotoRemoteDataSource extends BaseRemoteDataSource { | ||||
| abstract class PhotoRemoteDataSource extends BaseDataSource { | ||||
|   Future<Photo> getPhoto(int id); | ||||
|   Future<List<Photo>> getAllPhotos({int? start, int? limit}); | ||||
| } | ||||
| @ -78,14 +78,31 @@ Several use cases are supported : | ||||
| * Classic usecase : | ||||
| 
 | ||||
| ```dart | ||||
| class Test extends AsyncUseCase<QueryParameters, List<Photo>>> { | ||||
| class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> { | ||||
|   const RetrieveAllAlbums(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FuturOrResult<List<Photo>>> call(QueryParameters? params) { | ||||
|      final photos = _photoRepository.getAllPhotos( | ||||
|   FutureOrResult<List<Album>> execute(QueryParameters params) { | ||||
|     final albums = _photoRepository.getAllAlbums( | ||||
|       start: params.start, | ||||
|       limit: params.limit, | ||||
|     ); | ||||
|     return albums; | ||||
|   } | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| * No parameter usecase : | ||||
| 
 | ||||
| ```dart | ||||
| class DisplayFavorites extends NoParamsAsyncUseCase<List<Photo>> { | ||||
|   const DisplayFavorites(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>> execute() { | ||||
|     final photos = _photoRepository.getAllPhotosFromFavorites(); | ||||
|     return photos; | ||||
|   } | ||||
| } | ||||
| @ -94,48 +111,51 @@ class Test extends AsyncUseCase<QueryParameters, List<Photo>>> { | ||||
| You can add alternatve scenarios and check pre/post conditions using our extensions : | ||||
| 
 | ||||
| ```dart | ||||
| class SearchPhotos extends AsyncUseCase<QueryParameters, List<Photo>>> { | ||||
| class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> { | ||||
|   const RetrieveAllAlbums(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>>> call(QueryParameters? params) { | ||||
|      final photos = _photoRepository.getAllPhotos( | ||||
|   FutureOrResult<List<Album>> execute(QueryParameters params) { | ||||
|     final albums = _photoRepository.getAllAlbums( | ||||
|       start: params.start, | ||||
|       limit: params.limit, | ||||
|     ); | ||||
|     return photos; | ||||
|     return albums; | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(QueryParameters? params) { | ||||
|     if(params.start == null || params.limit == null){ | ||||
|       throw ClientException('Préconndition non valides'); | ||||
|     if (params.start < 0) { | ||||
|       throw const ClientException('Invalid start parameter'); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| You can implement error scenarios overriding `onError` , or check postconditions by overriding `onComplete` . | ||||
| You can implement error scenarios overriding `onException` , or check postconditions by overriding `onComplete` . | ||||
| 
 | ||||
| * Stream usecase : | ||||
| 
 | ||||
| ```dart | ||||
| class SearchPhotos extends StreamUseCase<QueryParameters, List<Photo>>> { | ||||
| class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> { | ||||
|   const RetrieveAllAlbums(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<Stream<List<Photo>>>> call(QueryParameters? params) { | ||||
|      final photos = _photoRepository.getAllPhotos( | ||||
|   FutureOrResult<List<Album>> execute(QueryParameters params) { | ||||
|     final albums = _photoRepository.getAllAlbums( | ||||
|       start: params.start, | ||||
|       limit: params.limit, | ||||
|     ); | ||||
|     return photos; | ||||
|     return albums; | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Album>> onException(Object e) => Ok([]); | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| On this case, observers allow you to add alternative scenarios when data changed, overriding `onData` or `onDone` . | ||||
| 
 | ||||
| Please note that to use handlers, call `call` method and not `execute` . | ||||
| 
 | ||||
| > In fact, here we need a new parameter object, so let's create it: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user