hisma_visual_monitor 0.3.1+1 hisma_visual_monitor: ^0.3.1+1 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();
}