docs(architecture): update Readme. (#38)
This commit is contained in:
parent
136e0e8c98
commit
00393a6ba7
@ -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<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) {
|
||||
final photos = _photoRepository.getAllPhotos(
|
||||
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
|
||||
@ -171,4 +220,4 @@ class PhotoRepositoryImpl extends PhotoRepository {
|
||||
}
|
||||
```
|
||||
|
||||
That's all.
|
||||
That's all.
|
||||
|
Loading…
x
Reference in New Issue
Block a user