Skip to content

Instantly share code, notes, and snippets.

@BrianCortes
Last active June 2, 2020 20:26
Show Gist options
  • Save BrianCortes/69a94417ab86b30c1b2bbe7f358f1c69 to your computer and use it in GitHub Desktop.
Save BrianCortes/69a94417ab86b30c1b2bbe7f358f1c69 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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