Skip to content

Instantly share code, notes, and snippets.

@muratbeser
Created July 11, 2020 15:49
Show Gist options
  • Select an option

  • Save muratbeser/ea0a22b2e9782d6c5fca89adbcdfcebc to your computer and use it in GitHub Desktop.

Select an option

Save muratbeser/ea0a22b2e9782d6c5fca89adbcdfcebc 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 fetchMachine = Machine(
{
id: 'app',
initial: 'initialize',
context: {
modules: [],
menu: [],
message: undefined
},
states: {
initialize: {
invoke: {
id: 'verifyJWT',
src: async () => {
return false;
},
onError: {
target: 'failureJWT',
actions: assign({
errorMessage: (context, event) => {
// event is:
// { type: 'error.execution', data: 'No query specified' }
return event.data;
}
})
},
onDone: {
target: 'successJWT',
actions: assign({ modules: (_, event) => event.data })
}
}
},
successJWT: {
invoke: {
id: 'loadModules',
src: async () => {
return [];
},
onError: {
target: 'failureLoadModules',
actions: assign({
errorMessage: (context, event) => {
// event is:
// { type: 'error.execution', data: 'No query specified' }
return event.data;
}
})
},
onDone: {
target: 'successLoadModules',
actions: assign({ modules: (_, event) => event.data })
}
}
},
failureJWT: {},
failureLoadModules: {},
successLoadModules: {}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment