Skip to content

Instantly share code, notes, and snippets.

@tmlangley
Created March 19, 2020 16:12
Show Gist options
  • Save tmlangley/af44687d41d03c5a1ca0b052ec4b20da to your computer and use it in GitHub Desktop.
Save tmlangley/af44687d41d03c5a1ca0b052ec4b20da 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 searchValid = (context, event) => {
// return context.canSearch && event.query && event.query.length > 0;
// };
const SwrfetchMachine = Machine({
id: 'swrFetch',
initial: 'idle',
context: {
retries: 0,
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
initial: 'validating',
states: {
validating: {
on: {
VALIDATION_COMPLETE: 'done'
}
},
done: {
type: 'final'
}
}
},
failure: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment