Skip to content

Instantly share code, notes, and snippets.

@AndreiCalazans
Last active October 27, 2019 19:58
Show Gist options
  • Save AndreiCalazans/757a7102d7c52a1595d47647c132644d to your computer and use it in GitHub Desktop.
Save AndreiCalazans/757a7102d7c52a1595d47647c132644d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
// const keepHistory = assign({
// screenHistory: (context, event) => [...context.screenHistory]
// });
const withScreenState = (rest) => ({
entry: "updateScreenHistory",
...rest
})
const LogInState = (backTo, eventOptions = {}) => ({
initial: 'idle',
on: {
back: backTo
},
states: {
idle: {
on: {
submit: 'validating',
...eventOptions,
}
},
validating: {
on: {
success: '#App.SelectSubscription'
}
},
ForgotPassword: {},
}
});
const SignInState = LogInState('SignIn', {
signup: '#App.SignUp',
forgotPassword: 'ForgotPassword'
});
const SignUpState = LogInState('SignIn', {
signin: '#App.SignIn',
forgotPassword: 'ForgotPassword'
})
const fetchMachine = Machine({
id: 'App',
initial: 'LaunchScreen',
states: {
LaunchScreen: {
on: {
"": [
{
target: 'Content',
cond: 'isUserSignedIn'
},
{
target: "SignIn"
}
]
}
},
SignIn: withScreenState({
...SignInState,
}),
SignUp: withScreenState({
...SignUpState,
}),
SelectSubscription: {},
SelectAccount: {},
CreateAccount: {},
DeleteAccount: {},
Content: {},
},
}, {
guards: {
isUserSignedIn: () => false
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment