create static method

Future<StateMachine> create(
  1. BuildGraph buildGraph, {
  2. bool production = false,
})

Creates a statemachine using a builder pattern.

The production flag controls whether InvalidTransitionException are thrown. We recommend setting production to true for your release code as it makes your system more forgiving to odd events that are sent when the FSM doesn't expect them. Instead these transitions are logged.

production defaults to false.

Implementation

static Future<StateMachine> create(BuildGraph buildGraph,
    {bool production = false}) async {
  final graphBuilder = GraphBuilder();

  buildGraph(graphBuilder);
  final machine =
      StateMachine._(graphBuilder.build(), production: production);
  await machine._load();

  if (!production) {
    if (!machine.analyse()) {
      throw InvalidStateMachine('Check logs');
    }
  }

  return machine;
}