Created
May 15, 2020 17:11
-
-
Save rakeshmenon/8066d7d00f2c881794021e0fc4b846dc 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
const fetchMachine = Machine({ | |
id: 'fetch', | |
initial: 'loading', | |
context: { | |
data: {}, | |
error: {}, | |
}, | |
states: { | |
loading: { | |
invoke: { | |
src: 'fetchData', | |
onDone: { | |
target: 'success', | |
actions: assign({ | |
data: (_, event) => event.data, | |
}), | |
}, | |
onError: { | |
target: 'failure', | |
actions: assign({ | |
error: (_, event) => event.data, | |
}), | |
}, | |
}, | |
}, | |
success: { | |
entry: 'postSuccess', | |
on: { | |
'': { | |
target: 'collapsed' | |
} | |
} | |
}, | |
failure: { | |
type: 'final', | |
}, | |
collapsed: { | |
entry: ['onCollapsed'], | |
on: { | |
'EXPAND': { | |
target: 'expanded' | |
}, | |
'FETCH': { | |
target: 'loading' | |
}, | |
} | |
}, | |
expanded: { | |
entry: ['onExpand'], | |
on: { | |
'COLLAPSE': { | |
target: 'collapsed' | |
}, | |
'FETCH': { | |
target: 'loading' | |
}, | |
} | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment