hisma_visual_monitor 0.3.1+2 copy "hisma_visual_monitor: ^0.3.1+2" to clipboard
hisma_visual_monitor: ^0.3.1+2 copied to clipboard

Visual monitor for Hisma, a hierarchical state machine implementation.

example/hisma_visual_monitor_example.dart

// ignore_for_file: avoid_print

import 'package:hisma/hisma.dart';
import 'package:hisma_visual_monitor/src/visual_monitor/client/visual_monitor.dart';

enum S { on, off }

enum E { turnOn, turnOff }

enum T { toOn, toOff }

StateMachine<S, E, T> createLightMachine({
  RegionList<S, E, T>? regions,
}) =>
    StateMachine<S, E, T>(
      name: 'lightMachine',
      events: E.values,
      initialStateId: S.off,
      states: {
        S.off: State(
          etm: {
            E.turnOn: [T.toOn],
          },
          onEntry: Action(
            description: 'Turning off.',
            action: (machine, dynamic arg) async => print('OFF'),
          ),
        ),
        S.on: State(
          etm: {
            E.turnOff: [T.toOff],
          },
          regions: regions,
          onEntry: Action(
            description: 'Turning on.',
            action: (machine, dynamic arg) async => print('ON'),
          ),
        ),
      },
      transitions: {
        T.toOn: Transition(to: S.on),
        T.toOff: Transition(to: S.off),
      },
    );

final lightMachine = createLightMachine();

Future<void> play() async {
  while (true) {
    await Future<void>.delayed(const Duration(seconds: 1));
    await lightMachine.fire(E.turnOn);
    await Future<void>.delayed(const Duration(seconds: 1));
    await lightMachine.fire(E.turnOff);
  }
}

Future<void> main() async {
  StateMachine.monitorCreators = [
    (machine) => VisualMonitor(machine),
  ];

  await lightMachine.start();
  await play();
}
2
likes
120
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

Visual monitor for Hisma, a hierarchical state machine implementation.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

hisma, logging, web_socket_channel

More

Packages that depend on hisma_visual_monitor