Last active
July 25, 2020 10:18
-
-
Save leeovery/ee62334a25f29826fe48bbeb2a01685d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const messagingMachine = Machine({ | |
id: 'messaging', | |
initial: 'idle', | |
context: { | |
// | |
}, | |
// either sending messages, receiving messages, or neither. | |
// can send and receive at same time. | |
type: 'parallel', | |
states: { | |
sending: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { INIT_SENDING: 'sending' }, | |
}, | |
sending: { | |
on: { | |
SENDING_COMPLETE: 'sent', | |
SENDING_FAILED: 'failed', | |
}, | |
}, | |
sent: { | |
on: { | |
'': 'idle', | |
}, | |
}, | |
failed: { | |
on: { | |
// resend message? | |
// how does it know which message to send? | |
// use message ID or have machine for the lifecycle of each message | |
// when message sent and rendered the machine can be discarded. | |
// the parent machine can orchastrate this | |
} | |
} | |
}, | |
}, | |
receiving: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { MESSAGE_RECEIVING: 'receiving' }, | |
}, | |
receiving: { | |
on: { MESSAGE_RECEIVED: 'received' }, | |
}, | |
received: { | |
on: { | |
'': 'idle', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, { | |
guards: { | |
// isAgent: (context) => context.userType === 'agent', | |
// isHomeowner: (context) => context.userType === 'homeowner', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment