Created
April 14, 2021 06:22
-
-
Save jschaf/34684de93bbdf1151d866e6220d422f8 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 machine = Machine({ | |
id: 'activeProduct', | |
initial: 'pristine', | |
strict: true, | |
context: { | |
name: {}, // product resource name | |
product: {}, // current active product | |
dirtyProduct: {}, // locally modified fields not yet submitted | |
submittingProduct: {}, // fields currently being submitted | |
seqSubmitFails: 0, // number of sequential submit failures | |
}, | |
states: { | |
// A pristine form matches the product in the DB. | |
pristine: { | |
on: { | |
MUTATE: {target: 'dirty', actions: ['mergeMutation']}, | |
}, | |
}, | |
// A dirty form differs from the product in the DB. | |
dirty: { | |
on: { | |
MUTATE: {target: 'dirty', actions: ['mergeMutation']}, | |
}, | |
after: {100: {target: 'submitting', actions: ['prepareSubmit']}}, | |
}, | |
// A form that is currently submitting. | |
submitting: { | |
invoke: { | |
id: 'product/submitting', | |
src: 'submitMutations', | |
onDone: [ | |
{cond: 'isPristine', target: 'pristine', actions: ['mergeSubmitted']}, | |
{target: 'dirty', actions: ['mergeSubmitted']}, | |
], | |
onError: { | |
target: 'dirty', | |
actions: ['handleSubmitFailure'], | |
}, | |
}, | |
on: { | |
MUTATE: {actions: ['mergeMutation']}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment