behaviour 0.0.5
behaviour: ^0.0.5 copied to clipboard
This package adds support for behaviours. Behaviours are classes of which the instances are used as functions.
example/behaviour_example.dart
import 'dart:async';
import 'package:behaviour/behaviour.dart';
class CreateCustomer extends Behaviour<CreateCustomerParams, void> {
@override
Future<void> action(CreateCustomerParams input, BehaviourTrack? track) {
// TODO logic to create a customer
return Future.value();
}
@override
String get description => 'creating client';
@override
FutureOr<Exception> onCatch(
Object e,
StackTrace stacktrace,
BehaviourTrack? track,
) {
return Exception('An unknown error occurred: $e');
}
}
class CreateCustomerParams {
const CreateCustomerParams({
required this.name,
required this.address,
required this.phoneNumber,
});
final String name;
final String address;
final String phoneNumber;
}
Future<void> main() async {
final createCustomer = CreateCustomer();
await createCustomer(const CreateCustomerParams(
name: 'Wim',
address: 'Somewhere in Belgium',
phoneNumber: '+32 xxx xx xx xx',
));
}