Skip to content

Instantly share code, notes, and snippets.

@faisal00813
Last active May 14, 2020 19:25
Show Gist options
  • Save faisal00813/d6555c2405875d7db34959f4aa5d5a04 to your computer and use it in GitHub Desktop.
Save faisal00813/d6555c2405875d7db34959f4aa5d5a04 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'connection',
initial: 'disconnected',
context: {
mode: 0
},
states: {
disconnected: {
on: {
CONNECT: 'init_connect'
}
},
init_connect: {
on: {
WIFI_CONNECT: 'init_wifi',
BT_CONNECT: 'init_bt'
}
},
init_bt: {
on: {
BT_AVAILABLE: 'attempt_connection',
BT_NOT_AVAILABLE: 'disconnected'
}
},
init_wifi: {
on: {
WIFI_AVAILABLE: 'attempt_connection',
WIFI_NOT_AVAILABLE: 'disconnected'
}
},
attempt_connection: {
on: {
CONNECTION_SUCCESS: 'connected',
CONNECTION_FAILED: 'disconnected'
}
},
connected: {
on: {
DISCONNECT: 'disconnected'
}
},
failure: {
on: {
RETRY: {
target: 'init_connect',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment