Skip to content

Instantly share code, notes, and snippets.

@doritostains
Last active March 18, 2020 09:30
Show Gist options
  • Save doritostains/6e27ee84755e7f50ead0bca2391ec1a0 to your computer and use it in GitHub Desktop.
Save doritostains/6e27ee84755e7f50ead0bca2391ec1a0 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 selectorCycle = {
states: {
loading: {
on: {
SUCCESS: 'ready',
FAIL: 'retry',
}
},
retry: {
on: {
SUCCESS: 'ready',
FAIL: '#vehicleSelect.loadError'
}
},
ready: {
on: {
SELECTED: '#vehicleSelect.makes'
}
}
}
}
const fetchMachine = Machine({
id: 'vehicleSelect',
initial: 'idle',
states: {
idle: {
on: {
START: 'years'
}
},
loadError: {
on: {
CLEAR: 'idle'
}
},
years: {
initial: 'loading',
on: {
NEXT: 'makes'
},
states: {
loading: {
on: {
SUCCESS: 'ready',
FAIL: 'retry',
}
},
retry: {
on: {
SUCCESS: 'ready',
FAIL: '#vehicleSelect.loadError'
}
},
ready: {
on: {
SELECTED: '#vehicleSelect.makes'
}
}
}
},
makes: {
initial: 'loading',
...selectorCycle
},
models: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
bodies: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
options: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
smartModels: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
smartSubmodels: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
smartSizes: {
initial: 'loading',
states: {
loading: {},
retry: {},
failed: {},
ready: {}
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment