Created
September 30, 2019 13:38
-
-
Save valscion/b817568c43d229d7af1b6749fe7452b3 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: [] | |
}, | |
// Global action handlers which will work for any state | |
on: { | |
CHANGE_OPTION: 'fetching', | |
CHANGE_TEXT_INPUT: 'debouncing' | |
}, | |
states: { | |
idle: {}, | |
debouncing: { | |
on: { | |
TEXT_INPUT_BLUR: 'fetching' | |
}, | |
after: [{ delay: 300, target: 'fetching' }] | |
}, | |
fetching: { | |
exit: ['clearPendingRequest'], | |
entry: ['startRequest'], | |
on: { | |
SEARCH_REQUEST_SUCCESS: { | |
target: 'idle', | |
actions: [handleRequestSuccess] | |
}, | |
SEARCH_REQUEST_FAILURE: { | |
target: 'error', | |
actions: ['handleRequestFailure'] | |
} | |
}, | |
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