Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Created March 24, 2021 13:55
Show Gist options
  • Save DaveHudson/27a8ca5c7e232446c3311182e29c6fa3 to your computer and use it in GitHub Desktop.
Save DaveHudson/27a8ca5c7e232446c3311182e29c6fa3 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