Last active
November 29, 2019 19:46
-
-
Save fakenickels/b0f95ec81cc5c81e1a8d8e853fb6e9a0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 notaFiscalMachine = { | |
id: 'notaFiscalMachine', | |
initial: 'issuing', | |
states: { | |
issuing: { | |
on: { | |
RESOLVE: 'issued', | |
REJECT: 'failure' | |
} | |
}, | |
issued: {type: 'final'}, | |
failure: { | |
on: { | |
RETRY: 'issuing', | |
} | |
}, | |
} | |
} | |
const chargeMachine = { | |
id: 'charge', | |
initial: 'generatePayment', | |
states: { | |
generatePayment: { | |
on: { | |
NEXT: 'awaitingPayment' | |
} | |
}, | |
awaitingPayment: { | |
on: { | |
RESOLVE: 'charged', | |
REJECT: 'failure', | |
}, | |
}, | |
charged: { | |
type: 'final', | |
...notaFiscalMachine, | |
}, | |
failure: {}, | |
} | |
} | |
const subscriptionMachine = { | |
id: 'subscription', | |
initial: 'generatePayment', | |
states: { | |
generatePayment: { | |
on: { | |
NEXT: 'awaitingPayment' | |
} | |
}, | |
awaitingPayment: { | |
on: { | |
RESOLVE: 'charged', | |
REJECT: 'failure', | |
}, | |
}, | |
charged: { | |
type: 'final', | |
on: { | |
NEXT: 'generatePayment', | |
}, | |
...notaFiscalMachine, | |
}, | |
failure: {}, | |
} | |
} | |
const fetchMachine = Machine({ | |
id: 'customer', | |
initial: 'invoice', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
invoice: { | |
on: { | |
ACCEPT_CHARGE: 'charge', | |
ACCEPT_SUBSCRIPION: 'subscription', | |
} | |
}, | |
charge: chargeMachine, | |
subscription: subscriptionMachine, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment