Last active
April 13, 2020 13:19
-
-
Save jaetask/bf95d53d70db2bbee6ae6c79e9b7c48d 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
const addressMachine = Machine({ | |
id: 'addresses', | |
initial: 'same_invoice_address', | |
context: { | |
address_line_1: '', | |
address_city: '', | |
address_postcode: '', | |
invoice_line_1: '', | |
invoice_city: '', | |
invoice_postcode: '', | |
}, | |
states: { | |
same_invoice_address: { | |
on: { | |
TOGGLE_SAME_INVOICE: { | |
target: 'different_invoice_address', | |
}, | |
ADDRESS_LINE_1: { | |
target: 'same_invoice_address', | |
actions: assign({ | |
address_line_1: (_, { value = '' }) => value, | |
invoice_line_1: (_, { value = '' }) => value, | |
}), | |
}, | |
ADDRESS_CITY: { | |
target: 'same_invoice_address', | |
actions: assign({ | |
address_city: (_, { value = '' }) => value, | |
invoice_city: (_, { value = '' }) => value, | |
}), | |
}, | |
ADDRESS_POSTCODE: { | |
target: 'same_invoice_address', | |
actions: assign({ | |
address_postcode: (_, { value = '' }) => value, | |
invoice_postcode: (_, { value = '' }) => value, | |
}), | |
}, | |
}, | |
}, | |
different_invoice_address: { | |
on: { | |
TOGGLE_SAME_INVOICE: { | |
target: 'same_invoice_address', | |
actions: assign({ | |
invoice_line_1: ctx => ctx.address_line_1, | |
invoice_city: ctx => ctx.address_city, | |
invoice_postcode: ctx => ctx.address_postcode, | |
}), | |
}, | |
ADDRESS_LINE_1: { | |
target: 'different_invoice_address', | |
actions: assign({ address_line_1: (_, { value = '' }) => value }), | |
}, | |
ADDRESS_CITY: { | |
target: 'different_invoice_address', | |
actions: assign({ address_city: (_, { value = '' }) => value }), | |
}, | |
ADDRESS_POSTCODE: { | |
target: 'different_invoice_address', | |
actions: assign({ address_postcode: (_, { value = '' }) => value }), | |
}, | |
INVOICE_LINE_1: { | |
target: 'different_invoice_address', | |
actions: assign({ invoice_line_1: (_, { value = '' }) => value }), | |
}, | |
INVOICE_CITY: { | |
target: 'different_invoice_address', | |
actions: assign({ invoice_city: (_, { value = '' }) => value }), | |
}, | |
INVOICE_POSTCODE: { | |
target: 'different_invoice_address', | |
actions: assign({ invoice_postcode: (_, { value = '' }) => value }), | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment