Skip to content

Instantly share code, notes, and snippets.

@blaadje
Last active April 8, 2021 13:15
Show Gist options
  • Save blaadje/bd3b1b1984d42fa6816202aa1fde165b to your computer and use it in GitHub Desktop.
Save blaadje/bd3b1b1984d42fa6816202aa1fde165b 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 paymentMethodService = () => {
const data = 'paymentMethod'
return Promise.resolve(data)
}
const paymentMethodMachine = Machine({
initial: 'idle',
id: 'paymentMethodMachine',
context: {},
states: {
idle: {
on: {
FETCH: {
target: 'loading'
}
}
},
loading:{
invoke: {
src: paymentMethodService,
onDone: {
target: 'success'
}
}
},
success:{},
failure:{}
}
})
const paymentMachine = Machine({
id: 'paymentMachine',
initial: 'idle',
context: {
paymentMethodsRef: null
},
states: {
idle: {
entry: assign({
paymentMethodsRef: () => spawn(paymentMethodMachine, 'paymentMethod')
}),
on: {
FETCH_PAYMENT_METHOD: {
actions: send('FETCH', {to: 'paymentMethod'})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment