skiff 0.3.0 copy "skiff: ^0.3.0" to clipboard
skiff: ^0.3.0 copied to clipboard

A lightweight Mediator implementation for Dart projects.

example/lib/main.dart

import 'dart:async';

import 'package:skiff/skiff.dart';

class FetchCharacters implements Request<FetchCharactersResult> {}

class FetchCharactersResult {
  final List<String> characters;

  FetchCharactersResult(this.characters);
}

class Authenticate implements Request<RequestResult> {
  final String username;
  final String password;

  Authenticate(this.username, this.password);
}

void main() async {
  var mediator = Mediator();

  var query = FetchCharacters();

  var charactersHandler =
      FuncHandler<FetchCharacters, FetchCharactersResult>((r) {
    return Future.value(FetchCharactersResult([
      'Eleven',
      'Mike Wheeler',
      'Dustin Henderson',
      'Jim Hopper',
      'Jonathan Byers',
      'Murray Bauman'
    ]));
  });

  mediator.addHandler(charactersHandler);

  var characters = await mediator.dispatch(query);
  characters.characters.forEach(print);

  var command = Authenticate('alexei@starcourtmall.com', 'pa55w0rd');

  var authenticationHandler = FuncHandler<Authenticate, RequestResult>((r) {
    return Future.value(RequestResult.succeeded());
  });

  mediator.addHandler(authenticationHandler);

  var result = await mediator.dispatch<RequestResult>(command);
  print('Login ${result.isSuccessful ? 'successful' : 'failed'}');
}
4
likes
150
points
41
downloads

Publisher

verified publisherhalesworth.org

Weekly Downloads

A lightweight Mediator implementation for Dart projects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on skiff