Skip to content

Instantly share code, notes, and snippets.

@sseletskyy
Last active September 19, 2021 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sseletskyy/e17eef70a3f1b1620d21ed8c81bc4272 to your computer and use it in GitHub Desktop.
Save sseletskyy/e17eef70a3f1b1620d21ed8c81bc4272 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'modalWindow',
initial: 'hidden',
context: {
submitDisabled: true,
closeDisabled: false,
},
states: {
hidden: {
on: {
OPEN: {
target: 'initialLoading',
actions: assign({
submitDisabled: true,
closeDisabled: false,
})
}
}
},
initialLoading: {
on: {
RESOLVE: {
target: 'initialSuccess',
actions: assign({
submitDisabled: false
})
},
REJECT: 'initialFailure'
}
},
initialSuccess: {
on: {
SUBMIT: {
target: 'submitting',
actions: assign({
submitDisabled: true,
closeDisabled: true
})
},
CLOSE: 'hidden'
}
},
initialFailure: {
on: {
RETRY: {
target: 'initialLoading'
},
CLOSE: 'hidden'
}
},
submitting: {
on: {
RESOLVE: {
target: 'submitSuccess',
actions: assign({
submitDisabled: false,
closeDisabled: false
})
},
REJECT: {
target: 'submitFailure',
actions: assign({
submitDisabled: false,
closeDisabled: false
})
}
}
},
submitSuccess: {
on: {
CLOSE: 'hidden'
}
},
submitFailure: {
on: {
SUBMIT: {
target: 'submitting',
actions: assign({
submitDisabled: true,
closeDisabled: true
})
},
CLOSE: 'hidden'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment