Last active
March 6, 2020 19:33
-
-
Save mapicard/0a02e3d39f7f364cf697a08140089ce8 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const getInfoStates = { | |
initial: 'getCaseName', | |
states: { | |
getCaseName: { | |
entry: ['aReqCaseName'], | |
on: { | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tRcvdCaseName: { | |
actions: ['aSaveCaseName'], | |
target: 'getCaseSize', | |
}, | |
}, | |
}, | |
getCaseSize: { | |
entry: ['aReqCaseSize'], | |
on: { | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tRcvdCaseSize: { | |
actions: ['aSaveCaseSize'], | |
target: 'end', | |
}, | |
} | |
}, | |
end: { | |
entry: 'Push_tGotInfo', | |
type: 'final', | |
} | |
} | |
}; | |
const getTracksStates = { | |
initial: 'getCaseName', | |
states: { | |
getCaseName: { | |
entry: ['aReqCaseName'], | |
on: { | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tRcvdCaseName: { | |
actions: ['aSaveCaseName'], | |
target: 'getCaseSize', | |
}, | |
}, | |
}, | |
getCaseSize: { | |
entry: ['aReqCaseSize'], | |
on: { | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tRcvdCaseSize: { | |
actions: ['aSaveCaseSize'], | |
target: 'end', | |
}, | |
} | |
}, | |
end: { | |
entry: 'Push_tGotInfo', | |
type: 'final', | |
} | |
} | |
}; | |
const goalMachine = Machine({ | |
id: 'goal', | |
initial: 'disconnected', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
disconnected: { | |
on: { | |
tGetSrvId: { | |
target: 'Open', | |
actions: ['aGetSrvId'], | |
}, | |
tGetInfo: { | |
target: 'Open', | |
actions: 'qGetInfo' | |
}, | |
tReqTrack: { | |
target: 'Open', | |
actions: 'aReqTrack' | |
}, | |
tGetTracks: { | |
target: 'Open', | |
actions: 'qGetTracks' | |
}, | |
tRetry: { | |
target: 'Open', | |
actions: 'aRetry' | |
}, | |
tTimeout: { | |
target: 'End', | |
actions: 'aEndComm' | |
}, | |
}, | |
}, | |
Open: { | |
entry: ['aOpen'], | |
on: { | |
tOpened: { | |
target: 'Opened', | |
actions: 'aOpened' | |
}, | |
tRetry: { | |
actions: 'aRetryStartComm' | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aStartCommError' | |
}, | |
tTimeout: { | |
target: 'End', | |
actions: 'aStartCommTmout' | |
}, | |
}, | |
}, | |
Opened: { | |
on: { | |
tGetTermId: { | |
target: 'TermId', | |
actions: 'aSendTermId' | |
}, | |
tAutoAccept: { | |
//target: 'OpenedIO', | |
}, | |
tServerId: { | |
//target: 'OpenedIO', | |
actions: 'aSaveSrvId' | |
}, | |
tHostVersion: { | |
//target: 'OpenedIO', | |
actions: 'aSaveSrvVer' | |
}, | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tOutputDone: { | |
//target: 'CommStarted', | |
actions: 'aOutReady' | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aError' | |
}, | |
} | |
}, | |
TermId: { | |
//entry: ['aSendTermId'], | |
on: { | |
tGetClientVer: { | |
target: 'ClientVer', | |
actions: ['aSendClientVersion'], | |
}, | |
tAutoAccept: { | |
//target: 'OpenedIO', | |
}, | |
tServerId: { | |
//target: 'OpenedIO', | |
actions: 'aSaveSrvId' | |
}, | |
tHostVersion: { | |
//target: 'OpenedIO', | |
actions: 'aSaveSrvVer' | |
}, | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tOutputDone: { | |
//target: 'CommStarted', | |
actions: 'aOutReady' | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aError' | |
}, | |
} | |
}, | |
ClientVer: { | |
on: { | |
tOutputDone: { | |
target: 'Connected', | |
actions: 'aOutReady' | |
}, | |
tInputReady: { | |
//target: 'OpenedIO', | |
actions: 'aReadToken' | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aError' | |
}, | |
} | |
}, | |
Connected: { | |
entry: ['aPopGoal'], | |
on: { | |
tGetSrvId: { | |
//target: 'Open', | |
actions: ['aGetSrvId'], | |
}, | |
tGetInfo: 'GetInfo', | |
tGetTracks: 'GetTracks', | |
tReqTrack: { | |
target: 'Open', | |
actions: 'aReqTrack' | |
}, | |
} | |
}, | |
GetInfo: { | |
on: { | |
tGotInfo: { | |
target: 'Connected', | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aError' | |
}, | |
}, | |
...getInfoStates | |
}, | |
GetTracks: { | |
on: { | |
tGotTracks: { | |
target: 'Connected', | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aError' | |
}, | |
}, | |
...getTracksStates | |
}, | |
End: { | |
type: 'final' | |
}, | |
getSrvId: { | |
//...connectionStates, | |
}, | |
start: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
on: { | |
RESOLVE: 'success', | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'loading', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
// action implementations | |
commStart: (context, event) => { | |
console.log('commStarting...'); | |
socket.open("1.2.3.4", 1234, | |
()=> { //success callback | |
}, | |
(err)=> { //error callback | |
} | |
); | |
}, | |
activate: (context, event) => { | |
console.log('activating...'); | |
}, | |
notifyActive: (context, event) => { | |
console.log('active!'); | |
}, | |
notifyInactive: (context, event) => { | |
console.log('inactive!'); | |
}, | |
sendTelemetry: (context, event) => { | |
console.log('time:', Date.now()); | |
} | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment