Last active
June 8, 2020 11:29
-
-
Save juboba/c36313d91403cc70a78719ba1b715994 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
context: { | |
defaultFormData: {}, | |
formData: {}, | |
}, | |
entry: 'setInitialDefaultFormData', | |
id: 'Editor Machine', | |
initial: 'idle', | |
states: { | |
editMode: { | |
initial: 'editing', | |
states: { | |
discarding: { | |
on: { | |
CANCEL: 'editing', | |
DISCARD: '#viewMode', | |
}, | |
}, | |
editing: { | |
on: { | |
DISCARD: 'discarding', | |
SET_ITEM: 'discarding', | |
SUBMIT: 'submitting', | |
}, | |
}, | |
submitting: { | |
initial: 'forking', | |
states: { | |
creating: { | |
invoke: { | |
onDone: { | |
target: '#viewMode', | |
}, | |
src: 'createItem', | |
}, | |
}, | |
forking: { | |
on: { | |
'': [ | |
{ | |
cond: 'isNew', | |
target: 'creating', | |
}, | |
{ | |
cond: 'isOld', | |
target: 'updating', | |
}, | |
] | |
} | |
}, | |
updating: { | |
entry: 'justLog', | |
invoke: { | |
onDone: { | |
target: '#viewMode', | |
}, | |
src: 'updateItem', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
idle: { | |
entry: 'check', | |
id: 'idle', | |
on: { | |
SET_ITEM: 'viewMode', | |
}, | |
}, | |
viewMode: { | |
id: 'viewMode', | |
on: { | |
EDIT: 'editMode', | |
SET_ITEM: 'viewMode', | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
justLog: console.log.bind('', 'justLog::'), | |
}, | |
guards: { | |
isNew: (_, { item }) => !item || !item.id, | |
isOld: (_, { item }) => item && item.id, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment