Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Last active September 2, 2020 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexFrazer/00cad5603f6474a2b4c36ea922c6790e to your computer and use it in GitHub Desktop.
Save AlexFrazer/00cad5603f6474a2b4c36ea922c6790e 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 stylesMachine = Machine({
id: 'overlapping_styles',
initial: 'idle',
context: {
event_id: null,
overlapping: [],
styles: [],
error: null,
},
states: {
idle: {
on: {
FETCH: 'loading_overlapping',
SET_EVENT: {
target: 'loading_overlapping',
actions: assign({
event_id: (_, event) => event.id,
}),
}
}
},
loading_overlapping: {
invoke: {
src: 'fetch_overlapping',
onDone: {
target: 'loading_styles',
actions: assign({
overlapping: (_, event) => event.data,
})
},
onError: {
target: 'overlapping_rejected',
actions: assign({
error: (_, event) => event.error,
})
}
}
},
loading_styles: {
invoke: {
src: 'fetch_styles',
onDone: {
target: 'styles_fulfilled',
actions: assign({
styles: (_, event) => event.data,
})
},
onError: {
target: 'styles_rejected',
actions: assign({
error: (_, event) => event.error,
})
}
}
},
styles_fulfilled: {
type: 'final',
},
styles_rejected: {
on: {
RETRY: 'loading_styles',
}
},
overlapping_rejected: {
on: {
BAD_REQUEST: 'bad_request',
INTERNAL_SERVER_ERROR: 'internal_server_error'
}
},
bad_request: {
on: {
REQUEST: 'loading_styles',
}
},
internal_server_error: {
type: 'final',
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment