Skip to content

Instantly share code, notes, and snippets.

@leeovery
Last active August 27, 2020 18:13
Show Gist options
  • Save leeovery/247cd78e57aab9a9f41ca6eabb0b73e3 to your computer and use it in GitHub Desktop.
Save leeovery/247cd78e57aab9a9f41ca6eabb0b73e3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'ready',
context: {},
states: {
ready: {
invoke: [{
src: 'listenForRecipientTyping',
}, {
src: 'listenForIncomingMessages',
}],
initial: 'idle',
states: {
idle: {
on: {
'RECIPIENT.TYPING.START': 'recipientTyping'
}
},
recipientTyping: {
on: {
'RECIPIENT.TYPING.STOP': {
target: 'idle'
}
}
}
},
on: {
'STACK.PUSH': {
actions: 'pushMessageOnToStack'
},
'MESSAGE.SEND': [
{
cond: 'isValidMessage',
//target: 'ready.sending.send',
actions: [
'createMessageAndPushToStack',
'clearMessageInput'
]
},
],
'USER.TYPING': {
actions: 'sendUserTypingEvent'
},
},
},
}
}, {
guards: {
isValidMessage: () => true,
},
services: {
listenForRecipientTyping: () => {
alert('listenForRecipientTyping')
},
listenForIncomingMessages: () => {
alert('listenForIncomingMessages')
}
},
actions: {
pushMessageOnToStack: () => {
alert('pushMessageOnToStack')
},
sendUserTypingEvent: () => {
alert('sendTypingEvent')
},
createMessageAndPushToStack: () => {
alert('createMessageAndPushToStack')
},
clearMessageInput: () => {
alert('clearMessageInput')
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment