Skip to content

Instantly share code, notes, and snippets.

@Lucasdsk
Last active May 29, 2020 17:54
Show Gist options
  • Save Lucasdsk/8a0a6e98fc2e936e3c2cb53c8a46eae6 to your computer and use it in GitHub Desktop.
Save Lucasdsk/8a0a6e98fc2e936e3c2cb53c8a46eae6 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 openingMachine = Machine({
id: 'opening',
initial: 'idle',
context: {
message: ''
},
states: {
idle: {
on: {
PUBLISH: 'publishing',
SAVE: 'saving'
}
},
publishing: {
initial: 'loading',
states: {
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final',
},
failure: {
actions: assign({
message: 'Erro ao publicar'
})
}
},
onDone: {
target: 'idle',
actions: assign({
message: 'Vaga publicada'
})
}
},
saving: {
initial: 'loading',
states: {
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final',
},
failure: {
invoke: {
src: () => Promise.reject(),
onError: {
target: '#opening.idle',
actions: assign({
message: 'Erro ao salvar'
})
}
}
}
},
onDone: {
target: 'idle',
actions: assign({
message: 'Vaga Salva'
})
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment