Skip to content

Instantly share code, notes, and snippets.

@xavhan
Last active May 27, 2020 14:23
Show Gist options
  • Save xavhan/74527b62bc1a71859916e52e19852635 to your computer and use it in GitHub Desktop.
Save xavhan/74527b62bc1a71859916e52e19852635 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'report',
initial: 'idle',
context: {
answers: 0,
},
states: {
idle: {
on: {
CREATE_REPORT: 'filled'
}
},
filled: {
on: {
DELETE_DRAFT: 'idle',
SAVE_ONLINE: 'synced',
ADD_ANSWER: {
target: 'filled',
actions: 'add',
},
DEL_ANSWER: {
target: 'filled',
actions: 'del'
}
},
},
synced: {
on: {
'': {
target: 'submitted',
cond: 'sup',
},
EDIT_ANSWERS: 'filled',
}
},
submitted: {
type: 'final'
},
},
actions: {
add: assign({
answers: (context, event) => context.answers + 1
}),
del: assign({
answers: (context, event) => context.answers - 1
}),
},
guards: {
sup: context => context.answers > 1
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment