Skip to content

Instantly share code, notes, and snippets.

@valscion
Created September 30, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valscion/6c3e7b6824b2adc47a71759ef3e78ab4 to your computer and use it in GitHub Desktop.
Save valscion/6c3e7b6824b2adc47a71759ef3e78ab4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const handleRequestSuccess = assign({
results: (_ctx, event) => event.results
});
const searchStateMachine = Machine({
id: 'search',
initial: 'idle',
context: {
results: []
},
states: {
idle: {
on: {
CHANGE_OPTION: 'fetching'
}
},
fetching: {
exit: ['clearPendingRequest'],
entry: ['startRequest'],
on: {
SEARCH_REQUEST_SUCCESS: {
target: 'idle',
actions: [handleRequestSuccess]
},
SEARCH_REQUEST_FAILURE: {
target: 'error',
actions: ['handleRequestFailure']
},
CHANGE_OPTION: 'fetching'
},
initial: 'fast',
states: {
fast: {
after: [{ delay: 500, target: 'slow' }]
},
slow: {
type: 'final'
}
}
},
error: {
on: {
'': {
target: 'idle'
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment