docs(architecture): update Readme. (#38)

This commit is contained in:
AN12345 2022-11-23 16:49:10 -05:00
parent 2467bc306a
commit 02ea266c43

View File

@ -31,10 +31,10 @@ The Wyatt Architecture for Flutter.
## Features ## Features
* Usecase - Usecase
* Repository - Repository
* DataSource - DataSource
* Entity - Entity
## Usage ## 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<Parameters, ReturnType>` : And finaly create your different usecases :
Several use cases are supported :
- Classic usecase :
```dart ```dart
class RetrieveAllPhoto extends UseCase<QueryParameters, List<Photo>> { class Test extends AsyncUseCase<QueryParameters, List<Photo>>> {
final PhotoRepository _photoRepository;
RetrieveAllPhotos(this._photoRepository);
@override @override
FutureResult<List<Photo>> call(QueryParameters params) { FuturOrResult<List<Photo>>> call(QueryParameters? params) {
final photos = _photoRepository.getAllPhotos( final photos = _photoRepository.getAllPhotos(
start: params.start, start: params.start,
limit: params.limit, limit: params.limit,
); );
@ -94,6 +95,54 @@ class RetrieveAllPhoto extends UseCase<QueryParameters, List<Photo>> {
} }
``` ```
You can add alternatve scenarios and check pre/post conditions using our extensions :
```dart
class SearchPhotos extends AsyncUseCase<QueryParameters, List<Photo>>> {
@override
FutureOrResult<List<Photo>>> call(QueryParameters? params) {
final photos = _photoRepository.getAllPhotos(
start: params.start,
limit: params.limit,
);
return photos;
}
@override
FutureOr<void> 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<QueryParameters, List<Photo>>> {
@override
FutureOrResult<Stream<List<Photo>>>> 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: > In fact, here we need a new parameter object, so let's create it:
```dart ```dart