mutation 0.2.1

  • README.md
  • Example
  • Installing
  • Versions
  • 49

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 packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.2.1 Dec 22, 2018 Go to the documentation of mutation 0.2.1 Download mutation 0.2.1 archive
0.2.0 Dec 21, 2018 Go to the documentation of mutation 0.2.0 Download mutation 0.2.0 archive
0.1.2 Dec 20, 2018 Go to the documentation of mutation 0.1.2 Download mutation 0.1.2 archive
0.1.1 Dec 20, 2018 Go to the documentation of mutation 0.1.1 Download mutation 0.1.1 archive
0.1.0 Dec 20, 2018 Go to the documentation of mutation 0.1.0 Download mutation 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
40
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.10

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Format lib/mutation.dart.

Run dartfmt to format lib/mutation.dart.

Maintenance issues and suggestions

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

Homepage URL does not exists. (-20 points)

We were unable to access https://github.com/aloisdeniel/dart_mutate at the time of the analysis.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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