From 18b1daa922353440e29c6626a53190d8a938b449 Mon Sep 17 00:00:00 2001 From: AN12345 Date: Wed, 23 Nov 2022 16:40:58 -0500 Subject: [PATCH] feat(architecture): add obsevers for alternative usecase scenarions (#38) --- .../lib/src/domain/usecases/observers.dart | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/wyatt_architecture/lib/src/domain/usecases/observers.dart diff --git a/packages/wyatt_architecture/lib/src/domain/usecases/observers.dart b/packages/wyatt_architecture/lib/src/domain/usecases/observers.dart new file mode 100644 index 00000000..370546fe --- /dev/null +++ b/packages/wyatt_architecture/lib/src/domain/usecases/observers.dart @@ -0,0 +1,44 @@ +// Copyright (C) 2022 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// 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, +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'dart:async'; + +import 'package:wyatt_architecture/wyatt_architecture.dart'; + +/// Usecase observers +mixin Observer { + /// Called before usecase is runned. + /// Usefull to check the preconditions + FutureOr onStart(Parameters? params) {} + + /// Called when error occures during main scenario + /// Usefull to run alternative scenario + FutureOr onError(AppException? error) {} +} + +/// Specific observer for classic usecase +mixin AsyncObserver { + FutureOr onComplete(ReturnType? data) {} +} + +/// Specific observer for stream case usecase +mixin StreamObserver { + /// Replaces the data event handler of this subscription. + void onDone() {} + + /// Replaces the done event handler of this subscription. + void onData(ReturnType? data) {} +}