Last active
September 25, 2019 07:13
-
-
Save valscion/1ee3af035a83c5559673e4e6ab85d3e0 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 handleRequestSuccess = assign({ | |
results: (_ctx, event) => event.results | |
}); | |
const searchStateMachine = Machine({ | |
id: 'search', | |
initial: 'idle', | |
context: { | |
results: [] | |
}, | |
states: { | |
idle: { | |
on: { | |
CHANGE_OPTION: 'fetching' | |
} | |
}, | |
fetching: { | |
entry: ['startRequest'], | |
on: { | |
SEARCH_REQUEST_SUCCESS: { | |
target: 'idle', | |
actions: [handleRequestSuccess] | |
}, | |
SEARCH_REQUEST_FAILURE: { | |
target: 'error' | |
} | |
} | |
}, | |
error: { | |
on: { | |
'': { | |
target: 'idle' | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment