docs(architecture): update Readme. (#38)
This commit is contained in:
parent
136e0e8c98
commit
00393a6ba7
@ -31,10 +31,10 @@ The Wyatt Architecture for Flutter.
|
||||
|
||||
## Features
|
||||
|
||||
* Usecase
|
||||
* Repository
|
||||
* DataSource
|
||||
* Entity
|
||||
- Usecase
|
||||
- Repository
|
||||
- DataSource
|
||||
- Entity
|
||||
|
||||
## Usage
|
||||
|
||||
@ -75,16 +75,17 @@ abstract class PhotoRepository extends BaseRepository {
|
||||
|
||||
> 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
|
||||
class RetrieveAllPhoto extends UseCase<QueryParameters, List<Photo>> {
|
||||
final PhotoRepository _photoRepository;
|
||||
|
||||
RetrieveAllPhotos(this._photoRepository);
|
||||
class Test extends AsyncUseCase<QueryParameters, List<Photo>>> {
|
||||
|
||||
@override
|
||||
FutureResult<List<Photo>> call(QueryParameters params) {
|
||||
FuturOrResult<List<Photo>>> call(QueryParameters? params) {
|
||||
final photos = _photoRepository.getAllPhotos(
|
||||
start: params.start,
|
||||
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:
|
||||
|
||||
```dart
|
||||
|
Loading…
x
Reference in New Issue
Block a user