Skip to content

Instantly share code, notes, and snippets.

@bdchauvette
Created February 1, 2021 18:03
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 bdchauvette/4032480a26488880fcc63fc03f5bcbdd to your computer and use it in GitHub Desktop.
Save bdchauvette/4032480a26488880fcc63fc03f5bcbdd 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 hasMqttInfo = {
id: 'has_mqtt_info',
initial: 'preconnect',
states: {
preconnect: {
on: {
CONNECT: 'connecting'
}
},
connecting: {
on: {
UNAUTHORIZED: '#provisioned.fetching_mqtt_info',
CONNACK: 'connected'
}
},
connected: {
on: {
DISCONNECT: 'preconnect',
}
}
}
};
const provisioned = {
id: 'provisioned',
initial: 'idle',
states: {
idle: {
on: {
FETCH_MQTT_INFO: 'fetching_mqtt_info',
}
},
fetching_mqtt_info: {
on: {
UNAUTHORIZED: '#telematics.provisioning',
MQTT_INFO: 'has_mqtt_info'
}
},
has_mqtt_info: hasMqttInfo,
},
}
const vehicleMachine = Machine({
id: 'telematics',
initial: 'provisioning',
context: {
retries: 0
},
states: {
provisioning: {
on: {
FETCH_TOKEN: 'fetching',
}
},
fetching: {
on: {
UNAUTHORIZED: 'provisioning',
AUTH_TOKEN: 'provisioned',
}
},
provisioned
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment