Skip to content

Instantly share code, notes, and snippets.

@DVG
Last active May 13, 2021 11:27
Show Gist options
  • Save DVG/e2ad8d6c976e495e7d083e1799c091f2 to your computer and use it in GitHub Desktop.
Save DVG/e2ad8d6c976e495e7d083e1799c091f2 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 objectiveApiMachine = Machine({
id: 'api',
initial: 'idle',
context: {
objectives: []
},
states: {
idle: {
on: {
LOAD: 'loading',
NEW: 'create'
}
},
loading: {
on: {
SUCCESS: {
target: 'idle',
actions: assign({
objectives: (context, event) => [
{ id: 1 },
{ id: 2 }
]})
}
}
},
create: {
on: {
SUCCESS: {
target: 'idle',
actions: assign({
objectives: (context, event) => [
...context.objectives,
{ id: 4 }
]
})
},
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment