Created
July 21, 2020 22:15
-
-
Save entorenee/286ef0ee6e79d01f2380084e899b3379 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 fetchMachine = Machine({ | |
initial: 'idle', | |
context: { | |
results: [], | |
errorMessage: '', | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
on: { | |
// SUCCESS: 'success', | |
SUCCESS: { | |
target: 'success', | |
actions: 'setResults', | |
}, | |
FAILURE: { | |
target: 'failure', | |
actions: 'setError', | |
} | |
} | |
}, | |
success: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
failure: { | |
on: { | |
FETCH: 'loading' | |
} | |
} | |
} | |
}, { | |
actions: { | |
setResults: assign({ | |
results: (context, event) => event.data | |
}), | |
setError: assign({ | |
errorMesssage: (context, event) => event.message | |
}) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment