Skip to content




JAR services

API Explorer

Making decisions in Flux

So far, we've only been creating workflows that have two states and don't diverge in any way. Flux has the capability to decide which transition to take based on events. For this example, we'll be making a workflow of a payment system. A starting state simulates a checkout from a client. Another two states are for handling the chosen payment method. One is for retrieving card details while the other is for displaying bank information. How do we invoke a state based on a client's payment method? To do this, we create a transition for each payment method. We'll use a Flux input called payment that defines the chosen payment method and map it to $fluxEvent.

  1. Create a transition from the Checkout state to the Get Card Details state. When prompted for the event, type in card.
  2. Create another transition from the Checkout state to the Display Bank Information state. When prompted for the event, type in bank. Notice that checkout state shows a validation error. This is because we have defined the events of the transitions and $fluxEvent is not set. We'll fix that next.
  3. Select the Checkout state and go to the Mapper. Map payment from the Flux input to the $fluxEvent variable. At this point, the validation error should be gone.
  4. Provide an action for retrieving card details and displaying bank information state. For this example, we'll just log the process.

Creating a multi-transition Flux service

Creating a multi-transition Flux Service

To test, run the Flux service and set the value of payment to card. Notice that the card details state's action is invoked. Rerun the Flux service and this time set the value of payment to bank. This time, the bank detail state's action is invoked instead.

Running multi-transition Flux states

Running multi-transition Flux states

And just like that, you've told Flux how to make a decision. $fluxEvent is the variable that Flux checks and compares against all available transitions to decide how to proceed. All outcomes should be accounted for. This allows you to assign a transition that catches all other events.

Quickly navigate to states or transitions with validation issues

Use the shortcuts and to navigate to the next or previous Flux state or transition with a validation issue.

Navigating to Flux states or transitions with issues