Created
August 4, 2021 09:49
-
-
Save 40thieves/8132a431e8d5515ec327cf7d70e54342 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: 'http', | |
initial: 'idle', | |
context: { | |
data: [] | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
invoke: { | |
src: invokeFetchData, | |
onDone: { | |
target: 'success', | |
actions: assign({ | |
data: (context, event) => { | |
return [...context.data, event.data] | |
} | |
}) | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
} | |
} | |
}); | |
function invokeFetchData() { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve('Hello world!'); | |
}, 3000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment