Skip to content

Instantly share code, notes, and snippets.

@kmorin
Created September 2, 2022 18:18
Show Gist options
  • Save kmorin/8b32697ee63c83758d71a26be679aca2 to your computer and use it in GitHub Desktop.
Save kmorin/8b32697ee63c83758d71a26be679aca2 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 transportMachine = Machine({
id: 'transport',
initial: 'empty',
context: {
retries: 0
},
states: {
empty: {
on: {
CREATE: 'creating'
}
},
creating: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'creating',
actions: assign({
retries: (ctx, event) => ctx.retries +1
})
}
}
}
}
});
// const fetchMachine = Machine({
// id: 'fetch',
// initial: 'idle',
// context: {
// retries: 0
// },
// states: {
// idle: {
// on: {
// FETCH: 'loading'
// }
// },
// loading: {
// on: {
// RESOLVE: 'success',
// REJECT: 'failure'
// }
// },
// success: {
// type: 'final'
// },
// 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