Skip to content

Instantly share code, notes, and snippets.

@jonboiser
Last active August 24, 2020 17:12
Show Gist options
  • Save jonboiser/113db680a682c78b45b89d8b726c660b to your computer and use it in GitHub Desktop.
Save jonboiser/113db680a682c78b45b89d8b726c660b 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)
// Better version
const machine =
Machine({
id: 'copymodal',
initial: 'SELECT_CLASSROOM',
context: {
groups: [],
},
states: {
SELECT_CLASSROOM: {
on: {
fetchgroups: 'SELECT_GROUPS',
},
},
SELECT_GROUPS: {
// Event: { type: SELECT_GROUPS, classroomId }
initial: 'LOADING',
states: {
LOADING: {
invoke: {
src(context, event) {
return LearnerGroupResource.fetchCollection({
getParams: { parent: event.classroomId },
});
},
onDone: {
target: 'GROUPS_FETCHED',
actions: assign({ groups: (context, event) => event.data }),
},
onError: {
target: 'FAILED',
},
},
},
GROUPS_FETCHED: {
type: 'final'
},
FAILED: {},
},
// onDone: 'SUBMIT'
},
SUBMIT: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment