Last active
October 30, 2019 05:09
-
-
Save parties/0f8b8f754118cad1507fd3b77fb5ad72 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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