Last active
March 6, 2020 22:23
-
-
Save mapicard/f13936a5ab6d677da2446458aa552f60 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 states_getInfo_A = { | |
initial: 'start', | |
states: { | |
start: { | |
entry: ['aSendReqInfo_A'], | |
on: { | |
tInputReady: {actions:'aReadToken'}, | |
tRcvdSrvReqId: {target: 'SendId'}, | |
}}, | |
SendId: { | |
entry: ['aSendId'], | |
on: { | |
tInputReady: {actions: 'aReadToken'}, | |
tRcvdInfo_A: { | |
actions: ['aSaveInfo_A'], | |
target: 'end', | |
} | |
}}, | |
end: { | |
entry: 'Push_tGotInfo', | |
type: 'final', | |
} | |
} | |
}; | |
const states_getInfo_B = { | |
initial: 'start', | |
states: { | |
start: { | |
entry: ['aSendReqInfo_B'], | |
on: { | |
tInputReady: {actions:'aReadToken'}, | |
tRcvdInfo_C: { | |
actions: ['aSaveInfo_B'], | |
target: 'end', | |
} | |
}}, | |
end: { | |
entry: 'Push_tGotInfo', | |
type: 'final', | |
} | |
} | |
}; | |
const goalMachine = Machine({ | |
id: 'serverInfoProvider', | |
initial: 'disconnected', | |
context: { retries: 0 }, | |
states: { | |
disconnected: { | |
on: { | |
tGetInfo_A: { | |
target: 'Open', | |
actions: 'aPushGoal_GetInfo_A' | |
}, | |
tGetInfo_B: { | |
target: 'Open', | |
actions: 'aPushGoal_GetInfo_B' | |
}, | |
}, | |
}, | |
Open: { | |
entry: ['aSocketOpen'], | |
on: { | |
tOpenSuccess: { | |
target: 'Opened', | |
actions: 'aOpened' | |
}, | |
tRetry: [ | |
{ | |
actions: 'aOpenRetry', | |
cond: 'retryValid', | |
}, | |
{ | |
actions: 'aOpenTimeout', | |
target: 'End', | |
} | |
], | |
tNetError: { | |
target: 'End', | |
actions: 'aOpenError' | |
}, | |
}, | |
}, | |
Opened: { | |
on: { | |
tInputReady: {actions:'aReadToken'}, | |
tRcvdSrvInfo:{actions:'aSaveSrvInfo'}, | |
tRcvdSrvReqClientId: { | |
actions: 'aSendClientId' | |
}, | |
tSendSuccess:{target: 'ClientIdSent'}, | |
tNetError: { | |
target: 'End', | |
actions: 'aOpenedError' | |
}, | |
} | |
}, | |
ClientIdSent: { | |
//entry: ['aSendTermId'], | |
on: { | |
tInputReady: {actions:'aReadToken'}, | |
tRcvdSrvReqClientVer: { | |
actions: ['aSendClientVersion'], | |
}, | |
tSendSuccess:{target: 'ClientVerSent'}, | |
tNetError: { | |
target: 'End', | |
actions: 'aClientIdError' | |
}, | |
} | |
}, | |
ClientVerSent: { | |
on: { | |
tInputReady: {actions:'aReadToken'}, | |
tRcvdSessionId: { | |
actions: ['aSaveSessId'], | |
target: 'Connected', | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aClientVerError' | |
}, | |
} | |
}, | |
Connected: { | |
entry: ['aPopGoal'], | |
on: { | |
tGetInfo_A: 'GetInfo_A', | |
tGetInfo_B: 'GetInfo_B', | |
} | |
}, | |
GetInfo_A: { | |
on: { | |
tGotInfo: { | |
target: 'Connected', | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aGetInfoAError' | |
}, | |
}, | |
...states_getInfo_A | |
}, | |
GetInfo_B: { | |
on: { | |
tGotTracks: { | |
target: 'Connected', | |
}, | |
tNetError: { | |
target: 'End', | |
actions: 'aGetInfoBError' | |
}, | |
}, | |
...states_getInfo_B | |
}, | |
End: { | |
type: 'final' | |
}, | |
} | |
}, | |
{ | |
guards: { | |
retryValid: (context, event) => { | |
return true; | |
} | |
} | |
}, | |
{ | |
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