Skip to content

Instantly share code, notes, and snippets.

@devstojko
Last active February 7, 2020 00:06
Show Gist options
  • Select an option

  • Save devstojko/c67b44c4604b6c5b400ac93ea97d9564 to your computer and use it in GitHub Desktop.

Select an option

Save devstojko/c67b44c4604b6c5b400ac93ea97d9564 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)
const fetchLocations = () => {}
const mapMachine = Machine({
id: 'mapMachine',
initial: 'idle',
context: {
locations: undefined,
searchLocations: undefined,
from: '',
to: '',
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
search: {
invoke: {
}
},
loading: {
invoke: {
id: 'dataLoader',
src: (ctx, e) => fetchLocations(),
onDone: {
target: 'ready',
actions: assign({
locations: (ctx, e) => e.data
})
},
onError: {
target: 'failure',
actions: assign({
error: (ctx, e) => e.data
})
}
}
},
ready: {
initial: 'select',
states: {
select: {
on: {
SELECT_FROM: {
target: '#mapMachine.search',
actions: assign({
from: (ctx, e) => e.data
})
},
SELECT_TO: '#mapMachine.search',
SELECT_DATE: '#mapMachine.search',
SELECT_COUNTER: '#mapMachine.search'
},
}
}
},
failure: {
on: {
RETRY: 'loading'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment