Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created November 1, 2019 16:00
Show Gist options
  • Save bkamapantula/cf6f989b31f2310af7c356bcf9b954c8 to your computer and use it in GitHub Desktop.
Save bkamapantula/cf6f989b31f2310af7c356bcf9b954c8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
// first in idle state
// needs at least 3 characters to trigger FETCH
// otherwise continue in idle state
const fetchMachine = Machine({
id: 'search-suggestions',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
// type: 'final'
on: {
}
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment