Created
December 11, 2020 15:08
-
-
Save Platekun/a630115cc00dc702166a9d5165d62552 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
| Machine({ | |
| id: 'Unintegrated Tournaments', | |
| initial: 'setUp', | |
| context: {}, | |
| states: { | |
| disabled: { | |
| type: 'final', | |
| }, | |
| setUp: { | |
| on: { | |
| PROCESSED_LAST_STORED_STATE: [ | |
| // TODO: remove, is only use to test in QA | |
| { | |
| target: '#during.readyToPlay', | |
| cond: 'ifReadyToPlay', | |
| }, | |
| { | |
| target: 'setUp.polling', | |
| cond: 'ifTournamentDoesNotExist', | |
| }, | |
| { | |
| target: '#during.wonByABye', | |
| cond: 'isStateWonByABye', | |
| }, | |
| { target: 'before' }, | |
| ], | |
| }, | |
| // TODO: remove, is only use to test in QA | |
| initial: 'getContextLocalStorage', | |
| states: { | |
| fetchingTournament: { | |
| invoke: { | |
| src: 'fetchTournamentProvider', | |
| onDone: { | |
| target: 'restoring', | |
| actions: 'setTournament', | |
| }, | |
| onError: 'polling', | |
| }, | |
| }, | |
| // TODO: remove, is only use to test in QA | |
| getContextLocalStorage: { | |
| invoke: { | |
| src: 'getContextFromLocalStorage', | |
| onDone: { | |
| target: 'restoring', | |
| actions: 'setContextFromLocalStore', | |
| }, | |
| onError: 'fetchingTournament', | |
| }, | |
| }, | |
| polling: { | |
| invoke: { | |
| src: 'fetchTournamentProvider', | |
| onDone: { | |
| target: 'waiting', | |
| actions: 'setTournament', | |
| }, | |
| onError: 'failure', | |
| }, | |
| }, | |
| waiting: { | |
| after: { | |
| POLL_DELAY: [ | |
| { | |
| target: 'polling', | |
| cond: 'ifTournamentDoesNotExist', | |
| }, | |
| { | |
| target: 'restoring', | |
| }, | |
| ], | |
| }, | |
| }, | |
| failure: { | |
| on: { | |
| RETRY: 'polling', | |
| }, | |
| }, | |
| restoring: { | |
| entry: send('PROCESSED_LAST_STORED_STATE'), | |
| }, | |
| }, | |
| }, | |
| before: { | |
| on: { | |
| PROCESSING_PREVIOUS_STEPS: [{ target: 'during' }], | |
| }, | |
| initial: 'validatingTheCheckTime', | |
| states: { | |
| validatingTheCheckTime: { | |
| invoke: { | |
| src: 'checkingStartTime', | |
| onDone: { | |
| target: 'waitingCheckTime', | |
| actions: 'setCheckingTimeStarted', | |
| }, | |
| onError: 'failureCheckedTime', | |
| }, | |
| }, | |
| waitingCheckTime: { | |
| always: { | |
| target: 'processingBeforeSteps', | |
| cond: 'ifIsCheckInTime', | |
| }, | |
| after: { | |
| CHECKED_TIME_DELAY: { | |
| target: 'validatingTheCheckTime', | |
| cond: 'ifCurrentIsLessCheckedTime', | |
| }, | |
| }, | |
| }, | |
| failureCheckedTime: { | |
| on: { | |
| RETRY: 'validatingTheCheckTime', | |
| }, | |
| }, | |
| processingBeforeSteps: { | |
| entry: send('PROCESSING_PREVIOUS_STEPS'), | |
| }, | |
| }, | |
| }, | |
| during: { | |
| id: 'during', | |
| initial: 'checkIn', | |
| states: { | |
| checkIn: { | |
| on: { | |
| START_CHECK_IN: '.beginCheckInProcess', | |
| ERROR_TRANSITION: '.failureRequest', | |
| BACK_TRANSITION: { actions: 'backTransition' }, | |
| CHECKIN_PROCESS_COMPLETED: { | |
| target: '.CheckInProcessCompleted', | |
| actions: 'setCheckInCompleted', | |
| }, | |
| }, | |
| invoke: { | |
| src: 'validateAlreadyCheckedIn', | |
| }, | |
| initial: 'checkInBaseSteps', | |
| states: { | |
| checkInBaseSteps: { | |
| entry: 'addCheckInBaseSteps', | |
| }, | |
| beginCheckInProcess: { | |
| invoke: { | |
| src: 'startCheckInProcess', | |
| onDone: { | |
| target: 'CheckInProcessCompleted', | |
| actions: 'setCheckInCompleted', | |
| }, | |
| onError: 'failureCheckIn', | |
| }, | |
| }, | |
| CheckInProcessCompleted: { | |
| invoke: { | |
| src: 'logStepTransition', | |
| onDone: { | |
| target: '#during.waitNextMatch', | |
| }, | |
| }, | |
| }, | |
| failureCheckIn: { | |
| entry: send('ERROR_TRANSITION'), | |
| }, | |
| failureRequest: { | |
| entry: [ | |
| assign({ | |
| transitionView: 'SET_ERROR_VIEW', | |
| }), | |
| ], | |
| }, | |
| }, | |
| }, | |
| waitNextMatch: { | |
| on: { | |
| PROCESS_NEXT_MATCH_STEPS: [ | |
| { | |
| target: '#friendshipStatus.sendFriendRequest', | |
| cond: 'ifStateIsSendFriendRequest', | |
| }, | |
| { | |
| target: '#friendshipStatus.waitingOpponentToAcceptFriendRequest', | |
| cond: 'ifStateIsFriendRequestSent', | |
| }, | |
| { | |
| target: '#friendshipStatus.acceptFriendRequest', | |
| cond: 'ifStateIsAcceptFriendRequest', | |
| }, | |
| { | |
| target: '#during.readyToPlay', | |
| cond: 'ifMatchStateIsReadyToPlay', | |
| }, | |
| { | |
| target: '#during.wonByABye', | |
| cond: 'isMatchStateWonByABye', | |
| }, | |
| ], | |
| }, | |
| entry: 'setWaitingNextMatchSteps', | |
| initial: 'fetchMatch', | |
| states: { | |
| validateMatch: { | |
| always: { | |
| target: 'processingNextMatchSteps', | |
| cond: 'ifThereIsAMatch', | |
| }, | |
| after: { | |
| MATCH_DELAY: { | |
| target: 'fetchMatch', | |
| cond: 'isMatchEmpty', | |
| }, | |
| }, | |
| }, | |
| fetchMatch: { | |
| invoke: { | |
| src: 'fetchMatchProvider', | |
| onDone: { | |
| target: 'validateMatch', | |
| actions: 'setMatch', | |
| }, | |
| onError: { | |
| target: 'validateMatch', | |
| }, | |
| }, | |
| }, | |
| processingNextMatchSteps: { | |
| entry: send('PROCESS_NEXT_MATCH_STEPS'), | |
| }, | |
| noMatchYet: { | |
| target: 'fetchMatch', | |
| }, | |
| }, | |
| }, | |
| friendshipStatus: { | |
| id: 'friendshipStatus', | |
| states: { | |
| sendFriendRequest: { | |
| entry: 'setSendFriendRequest', | |
| }, | |
| waitingOpponentToAcceptFriendRequest: { | |
| entry: 'addSentFriendRequestSentSteps', | |
| on: { | |
| OPPONENT_ACCEPTED_FRIENDSHIP_REQUEST: '#during.readyToPlay', | |
| OPPONENT_DID_NOT_ACCEPT_FRIENDSHIP: { | |
| actions: ['logStepTransition', 'addFriendRequestNotAcceptedSteps'], | |
| }, | |
| REPORT_RESULTS: { | |
| target: '#during.readyToPlay.opponentDidNotAppear', | |
| actions: 'displayReportResultsView', | |
| }, | |
| }, | |
| invoke: { | |
| id: 'pollFriendshipStatus', | |
| src: context => (callback) => { | |
| const intervalId = setInterval(async () => { | |
| const isFriend = await Promise.resolve( | |
| context, | |
| ); | |
| if (isFriend) { | |
| callback('OPPONENT_ACCEPTED_FRIENDSHIP_REQUEST'); | |
| } | |
| }, context.timeToWaitToCheckForFriendRequest); | |
| const timeoutId = setTimeout(() => { | |
| callback('OPPONENT_DID_NOT_ACCEPT_FRIENDSHIP', { | |
| // eslint-disable-next-line max-len | |
| state: WAITING_FOR_OPPONENT_TO_ACCEPT_FRIEND_REQUEST_STEPS_IDS | |
| .OPPONENT_DID_NOT_SHOW_UP, | |
| }); | |
| }, | |
| context.timeAvailableForOpponentToAcceptFriendRequest); | |
| return () => { | |
| clearInterval(intervalId); | |
| clearTimeout(timeoutId); | |
| }; | |
| }, | |
| }, | |
| }, | |
| acceptFriendRequest: { | |
| entry: 'setOpponentSentFriendRequest', | |
| }, | |
| }, | |
| }, | |
| readyToPlay: { | |
| on: { | |
| REPORT_RESULTS_COMPLETED: '.reportResultsCompleted', | |
| REPORT_RESULTS: '.beginReportResults', | |
| BACK_TRANSITION: '.idle', | |
| }, | |
| initial: 'readyToPlayBaseSteps', | |
| states: { | |
| readyToPlayBaseSteps: { | |
| entry: ['addReadyToPlayBaseSteps'], | |
| }, | |
| idle: { | |
| entry: 'backTransition', | |
| }, | |
| opponentDidNotAppear: {}, | |
| beginReportResults: { | |
| entry: [ | |
| assign({ | |
| transitionView: 'SET_REPORT_RESULTS', | |
| }), | |
| ], | |
| }, | |
| reportResultsCompleted: { | |
| invoke: { | |
| src: 'logStepTransition', | |
| onDone: { | |
| actions: ['setBackCompetitiveView', 'addConfirmResultsBaseSteps'], | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| wonByABye: { | |
| on: { | |
| WON_BY_A_BYE_COMPLETED: { | |
| target: '.wonByAByeCompleted', | |
| actions: 'addWonByAByeBaseSteps', | |
| }, | |
| }, | |
| initial: 'wonByAByeBaseSteps', | |
| states: { | |
| wonByAByeBaseSteps: { | |
| entry: send('WON_BY_A_BYE_COMPLETED'), | |
| }, | |
| wonByAByeCompleted: { | |
| invoke: { | |
| src: 'logStepTransition', | |
| onDone: '#during.waitNextMatch', | |
| }, | |
| }, | |
| }, | |
| }, | |
| after: {}, | |
| }, | |
| }, | |
| }, | |
| }, { | |
| delays: { | |
| POLL_DELAY: context => context.tournamentInterval, | |
| CHECKED_TIME_DELAY: context => context.checkedInterval, | |
| MATCH_DELAY: context => context.matchInterval, | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment