Last active
June 2, 2020 20:26
-
-
Save BrianCortes/69a94417ab86b30c1b2bbe7f358f1c69 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 validateForm = () => true; | |
const createGroup = Machine({ | |
id: 'cohort', | |
initial: 'closed', | |
context: { | |
values: {}, | |
errors: {} | |
}, | |
states: { | |
closed: { | |
on: { | |
OPEN: 'opened' | |
} | |
}, | |
opened: { | |
initial: 'editing', | |
on: { | |
CLOSE: 'closed' | |
}, | |
states: { | |
editing: { | |
on: { | |
CHANGE: { | |
target: '', | |
actions: ['onChange'] | |
}, | |
SUBMIT: { | |
target: 'submitting', | |
cond: validateForm | |
} | |
} | |
}, | |
submitting: { | |
invoke: { | |
src: () => new Promise.resolve(), | |
onDone: 'success', | |
onError: 'error', | |
} | |
}, | |
success: { | |
onEntry: send('CLOSE') | |
}, | |
error: { | |
} | |
} | |
} | |
} | |
},{ | |
actions: { | |
// action to save | |
onChange: assign({ | |
values: (ctx, data) => { | |
const { event } = data; | |
return { | |
...ctx.values, | |
[event.name]: event.value | |
}; | |
} | |
}) | |
}, | |
guards: { | |
validateForm, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment