Last active
May 27, 2020 14:23
-
-
Save xavhan/74527b62bc1a71859916e52e19852635 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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