call method

bool call([
  1. dynamic payload
])

Execute this transition. Will call any tests registered via cancelIf, canceling the transition if any test returns true. Otherwise, the transition will occur and the machine will transition accordingly.

Returns true if the transition succeeded, false if it was canceled.

Implementation

bool call([payload]) {
  StateChange stateChange = StateChange._(_machine.current, _to, payload);

  // Verify the transition is valid from the current state.
  if (!_from.contains(stateChange.from) && !_from.contains(State.any)) {
    throw IllegalStateTransition(this, stateChange.from, stateChange.to);
  }

  // Allow transition to be canceled.
  for (int i = 0; i < _cancelTests.length; i++) {
    if (_cancelTests[i](stateChange)) return false;
  }

  // Transition is legal and wasn't canceled.
  // Update the machine state.
  _machine._transition(stateChange);

  // Notify listeners.
  _streamController.add(stateChange);
  return true;
}