Created
June 17, 2020 15:32
-
-
Save renerbaffa/076bedad38fc514066bce79f64513405 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 TIMEOUT = 3000 | |
Machine({ | |
id: 'fetchMachine', | |
initial: 'idle', | |
context: { | |
response: null, | |
error: null, | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading', | |
}, | |
}, | |
loading: { | |
entry: ['load'], | |
after: { | |
[TIMEOUT]: { | |
target: 'fail', | |
actions: assign({ | |
response: () => null, | |
error: 'error.timeout', | |
}), | |
}, | |
}, | |
on: { | |
RESOLVE: { | |
target: 'success', | |
actions: assign({ | |
response: (_, event) => event.data, | |
error: () => null, | |
}), | |
}, | |
REJECT: { | |
target: 'fail', | |
actions: assign({ | |
response: () => null, | |
error: (_, event) => event.error, | |
}), | |
}, | |
}, | |
}, | |
success: {}, | |
fail: {}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment