Skip to content

Instantly share code, notes, and snippets.

@Anveio
Last active November 9, 2020 15:40
Show Gist options
  • Save Anveio/e8ec8c7fa72cdfc4ddf23eba580bbeda to your computer and use it in GitHub Desktop.
Save Anveio/e8ec8c7fa72cdfc4ddf23eba580bbeda to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const confidentialMachine = Machine({
id: 'confidential',
initial: 'OFF',
context: {
dndEnabled: false,
retries: 0
},
on: {
ENABLE_DND: 'LOADING',
ACCESSORY_DISCONNECTED: 'DISABLED',
RESOLVE_ENABLE_DND: 'DISABLED',
},
states: {
OFF: {
on: {
TURN_ON: 'LOADING'
},
actions: assign({
featureEnabled: () => false
})
},
ON: {
on: {
TURN_OFF: 'LOADING'
},
actions: assign({
featureEnabled: () => true
})
},
DISABLED: {
},
LOADING: {
on: {
RESOLVE_ON: 'ON',
RESOLVE_OFF: 'OFF',
RESOLVE_ENABLE_DND: {
target: 'DISABLED',
actions: assign({
dndEnabled: () => true
})
},
RESOLVE_DISABLE_DND: {
actions: assign({
dndEnabled: () => false
})
},
ACCESSORY_COMMUNICATION_FAILURE: 'FAILURE'
}
},
FAILURE: {
on: {
RETRY: {
target: 'LOADING',
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