mutation 0.2.1

dart_mutate #

A state machine written in dart.

Examples #

Example #

class GoToA extends Event {}

class GoToB extends Event {}

class GoToC extends Event {}

class Start extends State {}

class A extends State {}

class B extends State {}

class C extends State {}

Future main() async {
  final dispatcher = Dispatcher(Start())
    ..from<Start>()
        .on<GoToA>((state, event) => A())
        .on<GoToC>((state, event) => C())
    ..from<A>().on<GoToB>((state, event) async {
      print(' .start');
      await Future.delayed(Duration(seconds: 1));
      print(' .end');
      return B();
    })
    ..from<B>().on<GoToC>((state, event) => C())
    ..end<C>();

  dispatcher.state.listen((s) {
    if (!dispatcher.isCompleted) {
      print('$s --> ' + dispatcher.supportedMutations.join("|"));
      print('next ?');
      final event = stdin.readLineSync().toLowerCase().trim();
      switch (event) {
        case 'a':
          dispatcher.dispatch(GoToA());
          break;
        case 'b':
          dispatcher.dispatch(GoToB());
          break;
        case 'c':
          dispatcher.dispatch(GoToC());
          break;
      }
    }
  });

  try {
    final last = await dispatcher.complete();
    print("Finished (${last.runtimeType})");
  } catch (e) {
    print("Error ($e)");
  }
}

example/main.dart

import 'package:mutation/mutation.dart';
import 'dart:io';

class GoToA extends Event {}

class GoToB extends Event {}

class GoToC extends Event {}

class Start extends State {}

class A extends State {}

class B extends State {}

class C extends State {}

Future main() async {
  final dispatcher = Dispatcher(Start())
    ..from<Start>()
        .on<GoToA>((state, event) => A())
        .on<GoToC>((state, event) => C())
    ..from<A>().on<GoToB>((state, event) async {
      print(' .start');
      await Future.delayed(Duration(seconds: 1));
      print(' .end');
      return B();
    })
    ..from<B>().on<GoToC>((state, event) => C())
    ..end<C>();

  dispatcher.state.listen((s) {
    if (!dispatcher.isCompleted) {
      print('$s --> ' + dispatcher.supportedMutations.join("|"));
      print('next ?');
      final event = stdin.readLineSync().toLowerCase().trim();
      switch (event) {
        case 'a':
          dispatcher.dispatch(GoToA());
          break;
        case 'b':
          dispatcher.dispatch(GoToB());
          break;
        case 'c':
          dispatcher.dispatch(GoToC());
          break;
      }
    }
  });

  try {
    final last = await dispatcher.complete();
    print("Finished (${last.runtimeType})");
  }
  catch(e) {
    print("Error ($e)");
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mutation: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mutation/mutation.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
36
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:mutation/mutation.dart.

Health suggestions

Fix lib/src/dispatcher.dart. (-0.50 points)

Analysis of lib/src/dispatcher.dart reported 1 hint:

line 91 col 11: Use rethrow to rethrow a caught exception.

Format lib/mutation.dart.

Run dartfmt to format lib/mutation.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/aloisdeniel/dart_mutate was unreachable.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0-dev <3.0.0
meta ^1.1.6 1.1.7
rxdart ^0.20.0 0.20.0 0.22.4