From 02ea266c43be8f069770a12171998e7b07fa16b7 Mon Sep 17 00:00:00 2001 From: AN12345 Date: Wed, 23 Nov 2022 16:49:10 -0500 Subject: [PATCH] docs(architecture): update Readme. (#38) --- packages/wyatt_architecture/README.md | 77 ++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 14 deletions(-) diff --git a/packages/wyatt_architecture/README.md b/packages/wyatt_architecture/README.md index 6a0e2acb..2ca22855 100644 --- a/packages/wyatt_architecture/README.md +++ b/packages/wyatt_architecture/README.md @@ -7,7 +7,7 @@ * the Free Software Foundation, either version 3 of the License, or * any later version. - * This program is distributed in the hope that it will be useful, + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. @@ -31,10 +31,10 @@ The Wyatt Architecture for Flutter. ## Features -* Usecase -* Repository -* DataSource -* Entity +- Usecase +- Repository +- DataSource +- Entity ## Usage @@ -73,19 +73,20 @@ abstract class PhotoRepository extends BaseRepository { } ``` -> Here the repository is just a proxy of the data sources with result type (to have beautiful error handling). +> Here the repository is just a proxy of the data sources with result type (to have beautiful error handling). -And finaly create your different usecases by using `UseCase` : +And finaly create your different usecases : + +Several use cases are supported : + +- Classic usecase : ```dart -class RetrieveAllPhoto extends UseCase> { - final PhotoRepository _photoRepository; - - RetrieveAllPhotos(this._photoRepository); +class Test extends AsyncUseCase>> { @override - FutureResult> call(QueryParameters params) { - final photos = _photoRepository.getAllPhotos( + FuturOrResult>> call(QueryParameters? params) { + final photos = _photoRepository.getAllPhotos( start: params.start, limit: params.limit, ); @@ -94,6 +95,54 @@ class RetrieveAllPhoto extends UseCase> { } ``` +You can add alternatve scenarios and check pre/post conditions using our extensions : + +```dart +class SearchPhotos extends AsyncUseCase>> { + + @override + FutureOrResult>> call(QueryParameters? params) { + final photos = _photoRepository.getAllPhotos( + start: params.start, + limit: params.limit, + ); + return photos; + } + + + @override + FutureOr onStart(QueryParameters? params) { + if(params.start == null || params.limit == null){ + throw ClientException('Préconndition non valides'); + } + } + +} +``` + +You can implement error scenarios overriding `onError`, or check postconditions by overriding `onComplete` . + +- Stream usecase : + +```dart +class SearchPhotos extends StreamUseCase>> { + + @override + FutureOrResult>>> call(QueryParameters? params) { + final photos = _photoRepository.getAllPhotos( + start: params.start, + limit: params.limit, + ); + return photos; + } + +} +``` + +On this case, observers allow you to add alternative scénarios when data changed, overriding `onData` or `onDone`. + +Please note that to use handlers, call `execute` methodes instead of `call`. + > In fact, here we need a new parameter object, so let's create it: ```dart @@ -171,4 +220,4 @@ class PhotoRepositoryImpl extends PhotoRepository { } ``` -That's all. \ No newline at end of file +That's all.