Last active
July 31, 2020 05:34
-
-
Save taoxuau/1362f802dfa9ab8b4b39cbe6b819b028 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 isStandard = (context, event) => context.currentStates === "Standard"; | |
const isDocumentaryInstruction = (context, event) => context.currentStates === "DocumentaryInstruction"; | |
const isSecondaryInstruction = (context, event) => context.currentStates === "SecondaryInstruction"; | |
const shipmentMachine = Machine( | |
{ | |
id: "shipment", | |
type: "parallel", | |
context: { | |
currentStates: "Standard" | |
}, | |
initial: 'select', | |
states: { | |
Standard: { | |
id: "standard", | |
initial: "select", | |
states: { | |
select: { | |
on: { | |
ADD_DOC: { target: "select", internal: true }, | |
ADD_DOCSET: { target: "select", internal: true }, | |
NEXT: { target: "#standard.draft", cond: isStandard }, | |
}, | |
}, | |
draft: { | |
on: { | |
ENTER_DATA: { target: "draft", internal: true }, | |
PREV: "select", | |
NEXT: "internalShare", | |
}, | |
}, | |
internalShare: { | |
on: { | |
PREV: "draft", | |
NEXT: "externalShare", | |
}, | |
}, | |
externalShare: { | |
on: { | |
PREV: "internalShare", | |
NEXT: "finalise", | |
}, | |
}, | |
finalise: { | |
on: { | |
APPLY_STAMP: { target: "finalise", internal: true }, | |
APPLY_SIGNATURE: { target: "finalise", internal: true }, | |
PREV: "externalShare", | |
NEXT: "distribute", | |
}, | |
}, | |
distribute: { | |
type: "final", | |
on: { | |
PREV: "finalise", | |
}, | |
}, | |
}, | |
}, | |
DocumentaryInstruction: { | |
id: "documentaryInstruction", | |
initial: "draft", | |
states: { | |
draft: { | |
on: { | |
ENTER_DATA: { target: "draft", internal: true }, | |
NEXT: { target: "distribute",cond: isDocumentaryInstruction }, | |
}, | |
}, | |
distribute: { | |
type: "final", | |
on: { | |
PREV: "draft", | |
}, | |
}, | |
}, | |
}, | |
SecondaryInstruction: { | |
initial: "externalShare", | |
states: { | |
externalShare: { | |
on: { | |
NEXT: { target: "collect", cond: isSecondaryInstruction }, | |
}, | |
}, | |
collect: { | |
type: "final", | |
on: { | |
PREV: "externalShare", | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
isStandard, | |
isDocumentaryInstruction, | |
isSecondaryInstruction | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment