initFSM method
void
initFSM(
- EventBus bus,
- T currentState, {
- T? lastState,
})
Implementation
void initFSM(EventBus bus, T currentState, {T? lastState}) {
// a repeated initFSM must not leave a second live subscription
_fsmSubscription?.cancel();
_fsmSubscription = null;
_fsm.bus = bus;
_state = currentState;
_lastState = lastState ?? currentState;
bool changeStateStart = false;
_fsmSubscription = bus.allEventStream.listen((e) async {
if (!changeStateStart) {
var topic = e.$1.topic;//Topic.fromParametr(type: e.$1.data.runtimeType);
var eventChannel = _fsm._map[topic];
if (eventChannel != null) {
var node = eventChannel[_state];
if (node != null && node.check(_state, _lastState, e.$1.data)) {
changeStateStart = true;
changeState(node.toState);
await node.call(_state, _lastState, e.$1.data,_ignoredDTO);
_ignoredDTO.clear();
changeStateStart = false;
}
}
} else
{
_ignoredDTO.add(e.$1);
}
});
}