Last active
March 11, 2023 11:09
-
-
Save mfoti/e7663b0f33f64fe341a9937fa931936b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const hapuStateMachine = Machine({ | |
id: 'toggle', | |
initial: 'idle', | |
context: { | |
sessionInfo: null, | |
sessionData: {}, | |
userData: {}, | |
metaData: null, | |
}, | |
states: { | |
idle: { | |
entry: ['initializeAction'], | |
on: { | |
startSession: { | |
target: 'introductionPage', | |
actions: [ | |
'startSession', | |
'navigateToIntroductionAction', | |
assign({ sessionInfo: { started: true } }) | |
], | |
}, | |
}, | |
}, | |
introductionPage: { | |
on: { | |
goToStep2: { | |
actions: ['step1Action'], | |
}, | |
goToStep3: { | |
actions: ['step2Action'], | |
}, | |
goToStep4: { | |
actions: ['step3Action'], | |
}, | |
saveUserData: { | |
actions: ['saveUserDataAction'], | |
}, | |
endIntroduction: { | |
actions: ['checkRegisterUserAction'], | |
}, | |
goToRegisterV2: { | |
actions: ['navigateToRegisterV2'], | |
target: 'registerV2', | |
}, | |
goToWelcome: { | |
actions: ['navigateToWelcomePage'], | |
target: 'welcome', | |
}, | |
}, | |
}, | |
registerV2: { | |
on: { | |
saveEmail: { | |
actions: ['saveUserDataAction'], | |
}, | |
// saveName: { | |
// actions: ['saveUserDataAction'], | |
// }, | |
returnToIntroduction: { | |
target: 'introductionPage', | |
actions: ['navigateToIntroductionAction'], | |
}, | |
registerUser: { | |
actions: ['saveUserDataAction', 'registerUserAction'], | |
}, | |
endRegisterUser: { | |
actions: ['navigateToWelcomePage'], | |
target: 'welcome', | |
}, | |
}, | |
}, | |
welcome: { | |
on: { | |
startGame: { | |
actions: ['navigateToGameInstantWinAction'], | |
target: 'gameInstantWin', | |
}, | |
}, | |
}, | |
gameInstantWin: { | |
on: { | |
iWcheckWin: { | |
actions: ['randomizeWinAction'], | |
}, | |
win: { | |
target: 'gameWin', | |
}, | |
lose: { | |
target: 'gameLose', | |
}, | |
}, | |
}, | |
gameWin: { | |
on: { | |
endGame: { | |
target: 'endGame', | |
}, | |
}, | |
}, | |
gameLose: { | |
on: { | |
endGame: { | |
target: 'endGame', | |
}, | |
}, | |
}, | |
endGame: { | |
entry: ['navigateToEndGameAction'], | |
on: { | |
next: { | |
target: 'giftInfo', | |
}, | |
}, | |
}, | |
giftInfo: { | |
entry: ['navigateToGiftInfoAction'], | |
}, | |
}, | |
actions: { | |
initializeAction: assign({ | |
metaData: (context) => { | |
return { | |
...context.metaData, | |
host: "my-hostname" | |
}; | |
} | |
}), | |
}, | |
}); | |
const serviceHapuMachine = interpret(hapuStateMachine).onTransition((state) => console.log(state.context)).start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment