Skip to content

Instantly share code, notes, and snippets.

@parties
Last active October 30, 2019 05:09
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 parties/0f8b8f754118cad1507fd3b77fb5ad72 to your computer and use it in GitHub Desktop.
Save parties/0f8b8f754118cad1507fd3b77fb5ad72 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// https://xstate.js.org/viz/?gist=0f8b8f754118cad1507fd3b77fb5ad72
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const inputMachine = Machine({
id: 'inputMachine',
initial: 'idle',
context: {
value: 0,
maxValue: 10,
},
states: {
idle: {
on: {
'': [
{ target: "valid", cond: (c, e) => c.value !== 0 && c.value < c.maxValue },
{ target: "error", cond: (c, e) => c.value >= c.maxValue }
],
UPDATE: {
target: "idle",
actions: assign({
value: (ctx, event) => ctx.value = event.data
})
}
}
},
// extend these two to communicate with a parent Machine
valid: {},
error: {}
}
}, {
guards: {
inputValid: (ctx, e) => ctx.value < ctx.maxValue
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment