Maxime Lechevallier
Maxime Lechevallier

Reputation: 1196

How can I combine 2 state machines in xstate 5

I have a machine that handles the processus of creating a product, which is used each time a user wants to create one.

Now I want to have a more guided onboarding for my new users, redirecting them to the product creation once they have filled their personal informations.

I want those 2 machines (onboarding + product) to be inter-connected, so the next/back targets each other initial/final states.

Upvotes: 2

Views: 520

Answers (1)

nik-kita
nik-kita

Reputation: 98

May be some ideas from this tiny implementation will be useful?

Open stately.ai to see/simulate onboard-machine and product-machine

onboarding-machine:

onboarding machine

product-machine:

product machine

some notes if illustration is not enough descriptive:

  • in this example onboard-machine is aka root, that at some moment can spawn product-machine or continue with previous is it already exists
  • spawn is possible only after the moment of email verification
  • but onboarding process can be paused
  • product creation also can be paused
  • so I hope I correctly understand next/back functional between machines
  • if product created new one can be started and onboarding is still processing at same time
  • the pause/resume functional is achieved by history pseudo-states

Upvotes: 1

Related Questions