Skip to content

Instantly share code, notes, and snippets.

@fiddlerwoaroof
Last active January 27, 2021 03:50
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 fiddlerwoaroof/6f4d41e8ebe81cffa3c77fd02b51084b to your computer and use it in GitHub Desktop.
Save fiddlerwoaroof/6f4d41e8ebe81cffa3c77fd02b51084b 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 machineDefinition = {
id: "address-book",
initial: "start",
context: { contacts: [] },
states: {
start: {
on: {
select_contact: "showing_contact",
new_contact: "adding_contact",
},
},
showing_contact: {type:'parallel', states:{a:{
initial: "viewing",
context: {
contact: {
name: "",
address: "",
phone_number: "",
},
},
states: {
viewing: {
on: {
edit_name: "editing_name",
edit_address: "editing_address",
edit_phone_number: "editing_phone_number",
},
},
editing_name: {
on: { save: "viewing" },
},
editing_address: {
on: { save: "viewing" },
},
editing_phone_number: {
on: { save: "viewing" },
},
},
on: {
deselect: "",
},
},b:{
initial: "viewing",
context: {
contact: {
name: "",
address: "",
phone_number: "",
},
},
states: {
viewing: {
on: {
edit_name: "editing_name",
edit_address: "editing_address",
edit_phone_number: "editing_phone_number",
},
},
editing_name: {
on: { save: "viewing" },
},
editing_address: {
on: { save: "viewing" },
},
editing_phone_number: {
on: { save: "viewing" },
},
},
on: {
deselect: "",
},
}}},
adding_contact: {
on: {
save: "showing_contact",
},
},
},
};
const fetchMachine = Machine(machineDefinition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment