Last active
June 18, 2021 23:57
-
-
Save kdgerona/a7c090b6bd1aa58a2757f3f165876813 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 context = { | |
application_config: { | |
max_attempts: 5, | |
}, | |
application_data: { | |
attempts: 0, | |
}, | |
}; | |
const implementations = { | |
actions: { | |
incrementAttempts: assign({ | |
application_data: ({ application_data }) => { | |
const { attempts } = application_data; | |
return { | |
...application_data, | |
attempts: attempts + 1, | |
}; | |
}, | |
}), | |
}, | |
guards: { | |
hasReachedMaxAttempts: ({ application_config, application_data }) => { | |
const { max_attempts } = application_config; | |
const { attempts } = application_data; | |
return attempts >= max_attempts; | |
}, | |
} | |
} | |
const config = { | |
initial: 'get_config', | |
context, | |
on: { | |
COMPONENT_UNMOUNT: { | |
target: 'done', | |
}, | |
}, | |
states: { | |
get_config: { | |
invoke: [ | |
{ | |
id: 'get-config', | |
src: 'getConfig', | |
}, | |
], | |
on: { | |
SUCCESS: { | |
actions: ['assignConfigs'], | |
target: 'loading_member_details', | |
}, | |
FAILED: { | |
target: 'error', | |
}, | |
}, | |
}, | |
loading_member_details: { | |
invoke: [ | |
{ | |
id: 'load-member-details', | |
src: 'loadMemberDetails', | |
}, | |
], | |
on: { | |
SUCCESS: { | |
actions: ['assignMemberDetails'], | |
target: 'done', | |
}, | |
FAILED: { | |
target: 'error', | |
}, | |
}, | |
}, | |
error: { | |
on: { | |
'': [ | |
{ | |
cond: 'hasReachedMaxAttempts', | |
target: 'timeout', | |
}, | |
{ | |
target: 'get_config', | |
actions: ['incrementAttempts'], | |
}, | |
] | |
} | |
}, | |
timeout: { | |
type: 'final', | |
}, | |
done: { | |
type: 'final', | |
}, | |
}, | |
} | |
Machine(config, implementations); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment