behaviour 0.0.3 copy "behaviour: ^0.0.3" to clipboard
behaviour: ^0.0.3 copied to clipboard

outdated

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',
  ));
}
1
likes
0
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

This package adds support for behaviours. Behaviours are classes of which the instances are used as functions.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async

More

Packages that depend on behaviour