Last active
March 26, 2020 09:03
-
-
Save the-main-thing/0fb764702c7ef8ab54fc165d65a2b122 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 CREATING_NEW_DOC = true | |
const workPeriodMachine = Machine({ | |
id: 'work-period', | |
initial: 'idle', | |
context: {}, | |
states: { | |
idle: { | |
on: { | |
SAVE: { | |
target: 'saving' | |
}, | |
DELETE: { | |
target: 'confirmDelete' | |
}, | |
CHANGE: { | |
actions: ['updateContext'] | |
}, | |
RESET: { | |
actions: ['resetContext'] | |
} | |
} | |
}, | |
saving: { | |
on: { | |
'': [ | |
{ | |
target: 'savingNew', | |
cond: 'creatingNewDoc' | |
}, | |
{ | |
target: 'savingChange', | |
cond: 'editingExistingDoc' | |
} | |
] | |
} | |
}, | |
savingNew: { | |
invoke: { | |
src: 'saveNewMutation', | |
onDone: { | |
target: 'idle', | |
actions: ['updateContext'] | |
}, | |
onError: { | |
target: 'mutationError' | |
} | |
} | |
}, | |
savingChange: { | |
invoke: { | |
src: 'saveChangesMutation', | |
onDone: { | |
target: 'idle', | |
}, | |
onError: { | |
target: 'mutationError' | |
} | |
} | |
}, | |
confirmDelete: { | |
on: { | |
CONFIRM: 'deleting', | |
CANCEL: 'idle' | |
} | |
}, | |
deleting: { | |
invoke: { | |
'src': 'removeMutation', | |
onDone: { | |
target: 'deleted' | |
}, | |
onError: { | |
target: 'mutationError', | |
} | |
} | |
}, | |
mutationError: { | |
on: { | |
CHANGE: 'idle', | |
DELETE: 'confirmDelete', | |
SAVE: 'saving', | |
RESET: { | |
target: 'idle', | |
actions: ['resetContext'] | |
} | |
} | |
}, | |
deleted: { | |
type: 'final' | |
} | |
} | |
}, { | |
guards: { | |
creatingNewDoc: () => CREATING_NEW_DOC, | |
editingExistingDoc: () => !CREATING_NEW_DOC | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment