Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active June 20, 2020 14: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 knownasilya/e4e49b317ff01b9c07c4722720e608a4 to your computer and use it in GitHub Desktop.
Save knownasilya/e4e49b317ff01b9c07c4722720e608a4 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 fetchMachine = Machine({
id: 'entity',
initial: 'idle',
on: {
SAVE: 'saving'
},
states: {
idle: {
on: {
AUTO_SAVE: {
actions: [
assign({
autoSavePayload: (_context, event) =>
event.payload
}),
actions.cancel('debounced-save'),
actions.send('SAVE', {
delay: 450,
id: 'debounced-save'
})
]
},
PUBLISH: 'publishing',
DELETE: 'deleted'
}
},
saving: {
invoke: {
id: 'updateBranchContent',
src: 'updateBranchContent',
onDone: {
target: 'idle',
actions: assign({
updateContentResult: (_context, event) => event.data
})
},
onError: {
target: 'savingFailed',
actions: [
assign({
updateContentError: (_context, event) =>
event.data
}),
'showErrorNotification'
]
}
},
on: {
SAVED: 'idle'
}
},
savingFailed: {
on: {
RETRY: 'saving'
}
},
publishing: {
invoke: {
id: 'publish',
src: 'publish',
onDone: {
actions: 'viewPublished'
},
onError: 'publishFailed'
}
},
publishFailed: {
on: {
RETRY: 'publishing'
}
},
deleted: {
entry: ['deletePr', 'deleteRecord'],
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment