Skip to content

Instantly share code, notes, and snippets.

@JanVoracek
Last active October 5, 2021 11:25
Show Gist options
  • Save JanVoracek/e3bb1ff632eb3f0815ea4c72e940f1c4 to your computer and use it in GitHub Desktop.
Save JanVoracek/e3bb1ff632eb3f0815ea4c72e940f1c4 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: 'shop-deployment',
initial: 'pending',
context: {
replicas: 0
},
states: {
pending: {
on: {
BUILD: 'building',
}
},
building: {
on: {
SUCCESS: 'sleeping',
FAILURE: 'failed',
}
},
sleeping: {
on: {
WAKE_UP: {
target: 'deploying',
},
}
},
deploying: {
on: {
DONE: {
target: 'running',
actions: assign({
replicas: (context, event) => 1
})
},
FAILURE: 'failed'
}
},
running: {
on: {
SLEEP: {
target: 'sleeping',
actions: assign({
replicas: (context, event) => 0
})
},
SCALE: {
target: 'running',
actions: assign({
replicas: (context, event) => context.replicas + 1
})
}
}
},
failed: {
type: 'final'
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment