Skip to content

Instantly share code, notes, and snippets.

@gretzky
Created February 16, 2021 16:41
Show Gist options
  • Save gretzky/191f0b9a9d7b97d737a0a936dd480463 to your computer and use it in GitHub Desktop.
Save gretzky/191f0b9a9d7b97d737a0a936dd480463 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const createDialMachine = Machine({
id: "createDialMachine",
initial: "init",
context: {
createDial: null,
error: false,
errorMsg: '',
retries: 0
},
states: {
init: {
on: {
DEVICE_ID: "deviceId"
}
},
deviceId: {
on: {
NEXT: "dialType",
EXIT: "init"
}
},
dialType: {
on: {
NEXT: "dialName",
EXIT: "init"
}
},
dialName: {
on: {
NEXT: "creating",
BACK: "dialType"
}
},
creating: {
on: {
RESOLVE: "complete",
REJECT: "failure"
}
},
complete: {
on: {
EXIT: "init",
ADD_ANOTHER: "deviceId"
}
},
failure: {
on: {
RETRY: {
target: 'creating',
actions: assign({
retries: (ctx, event) => ctx.retries + 1
})
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment