Skip to content

Instantly share code, notes, and snippets.

@laheadle
Created May 9, 2020 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laheadle/39a30b18abad8969bad0129c6d405758 to your computer and use it in GitHub Desktop.
Save laheadle/39a30b18abad8969bad0129c6d405758 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 querying = {
initial: 'fetchingPeriod',
states: {
fetchingPeriod: {
invoke: {
id: 'fetchperiod',
src: 'fetchperiod',
onDone: { target: 'scoring' },
onError: { target: '#topStories.sendError' }
},
},
scoring: {
on: {
'scored': 'drafting'
}
},
drafting: {
on: {
'drafted': 'fetchingEntities'
}
},
fetchingEntities: {
invoke: {
id: 'fetchEntities',
src: 'fetchEntities',
onDone: { target: '#topStories.ready', actions: ['sendQueryResult'] },
onError: { target: '#topStories.ready', actions: ['sendErrorResult'] },
},
},
}
};
const fetchMachine = Machine({
id: 'topStories',
initial: 'boot',
context: {
},
states: {
boot: {
on: {
receiveLenses: 'ready',
errorLenses: 'dead',
}
},
dead: {
type: 'final'
},
sendError: {
on: {
'': { target: 'ready', actions: ['sendErrorResult']
}
}
},
ready: {
on: {
query: [
{ target: 'ready', cond: 'cached' },
{target: 'querying'}
]
}
},
querying
}
}, {
guards: {
cached: () => false
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment