Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Last active March 15, 2021 14:07
Show Gist options
  • Save DaveHudson/85169975c23b249d146fdc60fef8e78b to your computer and use it in GitHub Desktop.
Save DaveHudson/85169975c23b249d146fdc60fef8e78b 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 fetchMachine = Machine({
id: 'XMPPChat',
initial: 'idle',
context: {
data: {
messages: {}
},
error: {}
},
states: {
idle: {
on: {
CREATE: {
target: '#XMPPChat.createXmppConnection'
}
}
},
createXmppConnection: {
invoke: {
src: 'createConnection',
onDone: {
target: "#XMPPChat.xmppClient.session:started",
actions: ["setSomething?"]
},
onError: {
target: "#XMPPChat.xmppClient.auth:failed",
actions: ["setError?"]
}
}
},
xmppClient: {
states: {
'session:started': {
invoke: {
src: 'getInbox',
onDone: {
target: '#XMPPChat.xmppClient',
actions: ['setInboxState']
},
onError: {}
}
},
message:{
invoke: {
src: 'messageReceived',
onDone: {
target: '#XMPPChat.xmppClient',
actions: ['setMessagesState']
},
onError: {}
}
},
'message:sent': {},
'groupchat': {},
'message:acked': {},
'message:hibernated': {},
'message:retry': {},
'message:failed': {},
disconnected: {
on: {
"": [
{
target: '#XMPPChat.createXmppConnection'
}
],
},
},
'auth:failed': {},
}
},
'window': {
on: {
ONLINE: {
target: '#XMPPChat.xmppClient.session:started'
},
OFFLINE: {
target: '#XMPPChat.xmppClient.disconnected'
},
}
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment