Last active
September 24, 2019 11:52
-
-
Save valscion/ad21cf41123bd4e6fba4264e23c0b013 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 handleRequestSuccess = assign({ | |
results: (_ctx, event) => event.results | |
}); | |
const handleHistoryPopState = assign({ | |
results: (_ctx, event) => event.results | |
}); | |
const searchStateMachine = Machine({ | |
id: 'search', | |
initial: 'boot', | |
context: { | |
results: [] | |
}, | |
states: { | |
boot: { | |
on: { | |
'': { | |
target: 'idle', | |
actions: ['replaceHistoryState', 'hookToHistory'] | |
} | |
} | |
}, | |
idle: { | |
on: { | |
HISTORY_POPSTATE: { | |
actions: [handleHistoryPopState] | |
}, | |
CHANGE_TEXT_INPUT: 'debouncing', | |
CHANGE_OPTION: 'fetching' | |
} | |
}, | |
debouncing: { | |
entry: ['startDebounceTimer'], | |
exit: ['clearDebounceTimer'], | |
on: { | |
HISTORY_POPSTATE: { | |
target: 'idle', | |
actions: [handleHistoryPopState] | |
}, | |
CHANGE_TEXT_INPUT: 'debouncing', | |
DEBOUNCE_TIMER: 'fetching', | |
CHANGE_OPTION: 'fetching' | |
} | |
}, | |
fetching: { | |
exit: ['clearSpinnerTimer', 'clearPendingRequest'], | |
entry: ['startRequest', 'startSpinnerTimer'], | |
on: { | |
CHANGE_TEXT_INPUT: 'debouncing', | |
CHANGE_OPTION: 'fetching', | |
HISTORY_POPSTATE: { | |
target: 'idle', | |
actions: [handleHistoryPopState] | |
}, | |
SEARCH_REQUEST_SUCCESS: { | |
target: 'idle', | |
actions: [handleRequestSuccess] | |
}, | |
SEARCH_REQUEST_FAILURE: { | |
target: 'error', | |
actions: ['handleRequestFailure'] | |
} | |
}, | |
initial: 'start', | |
states: { | |
start: { | |
on: { | |
TIMER: 'spinner' | |
} | |
}, | |
spinner: { | |
type: 'final' | |
} | |
} | |
}, | |
error: { | |
on: { | |
'': { | |
target: 'idle', | |
actions: ['logRequestError'] | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment