Last active
April 8, 2021 13:15
-
-
Save blaadje/bd3b1b1984d42fa6816202aa1fde165b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 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