Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Created December 2, 2019 16:43
Show Gist options
  • Save DaveHudson/4a50ca21c7c1a154923379ebbb824d8b to your computer and use it in GitHub Desktop.
Save DaveHudson/4a50ca21c7c1a154923379ebbb824d8b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const applicationMachine = Machine({
id: 'application',
initial: 'idle',
context: {},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: {
target: "loaded",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "error",
actions: assign({
data: (context, event) => event.data
})
},
}
},
loaded: {
on: {
SAVE: 'saving',
SUBMIt: 'submitting'
}
},
saving: {
on: {
RESOLVE: {
target: "saved",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "error",
actions: assign({
data: (context, event) => event.data
})
},
}
},
saved: {
type: 'final'
},
submitting: {
on: {
RESOLVE: {
target: "submitted",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "error",
actions: assign({
data: (context, event) => event.data
})
},
}
},
submitted: {
type: 'final'
},
error: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment