Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 25, 2021 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/9f823279ef735bb04d9f3f6955910742 to your computer and use it in GitHub Desktop.
Save ryanflorence/9f823279ef735bb04d9f3f6955910742 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const pageMachine = Machine({
id: 'pageTransition',
initial: 'idle',
context: {
location: '/',
nextLocation: null,
data: {},
forms: new Map(),
error: null
},
states: {
idle: {
on: {
GET: {
target: 'loading',
actions: assign({
nextLocation: (c, e) => e.location
})
},
POST: {
target: 'posting',
actions: assign({
nextLocation: (c, e) => e.location,
forms: (c, e) => {
forms.set(e.location.key, e.form)
return forms;
}
})
}
}
},
loading: {
on: {
RESOLVE: {
target: 'idle',
actions: assign({
data: (c, e) => e.data
})
},
LOADER_ERROR: {
target: 'idle',
actions: assign({
error: (c, e) => e.error,
data: (c, e) => e.data
})
},
MODULE_ERROR: 'reloading'
}
},
posting: {
on: {
RESOLVE: {
target: 'loading',
actions: assign({
nextLocation: (c, e) => e.location,
forms: (c, e) => {
c.forms.delete(e.formKey)
}
})
},
ACTION_ERROR: {
target: "idle",
actions: assign({
error: (c, event) => event.error,
data: (c, event) => event.data
})
}
}
},
reloading: {
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment