Skip to content

Instantly share code, notes, and snippets.

@flaviouk
Last active December 6, 2019 16:42
Show Gist options
  • Save flaviouk/dbe449df5a953ed2d66fdc9fa01c6575 to your computer and use it in GitHub Desktop.
Save flaviouk/dbe449df5a953ed2d66fdc9fa01c6575 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'marxent',
initial: 'PENDING',
context: {
token: null,
error: null,
},
states: {
PENDING: {
on: {
GET_TOKEN: 'GET_TOKEN',
},
},
FAILURE: {
type: 'final',
},
GET_TOKEN: {
invoke: {
id: 'getDesignToken',
src: (_context, event) => Promise.resolve(event),
onDone: {
target: 'INITIALISE_JS_COMMUNICATOR',
actions: assign({
token: (_context, event) => event.data.token,
vendorId: (_context, event) => event.data.vendorId,
}),
},
onError: {
target: 'FAILURE',
actions: assign({ error: (_context, event) => event.data }),
},
},
},
INITIALISE_JS_COMMUNICATOR: {
on: {
SUCCESS: 'WAIT_FOR_EVENTS',
FAILURE: 'FAILURE',
},
},
WAIT_FOR_EVENTS: {
on: {
DesignCreated: 'OPEN_CREATE_DESIGN_NAME_MODAL',
DesignSaved: 'EDIT_DESIGN',
BomSaved: 'OPEN_BOM_MODAL',
},
},
OPEN_CREATE_DESIGN_NAME_MODAL: {
on: {
SUCCESS: 'CREATE_DESIGN',
FAILURE: 'FAILURE',
CANCEL: 'WAIT_FOR_EVENTS',
},
},
OPEN_BOM_MODAL: {
on: {
CANCEL: 'WAIT_FOR_EVENTS',
},
},
CREATE_DESIGN: {
invoke: {
id: 'postDesign',
src: (context, event) => Promise.resolve({ data: 'asd' }),
onDone: {
target: 'WAIT_FOR_EVENTS',
},
onError: {
target: 'FAILURE',
actions: assign({ error: (context, event) => event.data }),
},
},
},
EDIT_DESIGN: {
invoke: {
id: 'patchDesign',
src: (context, event) => Promise.resolve({ data: 'asd' }),
onDone: {
target: 'WAIT_FOR_EVENTS',
},
onError: {
target: 'FAILURE',
actions: assign({ error: (context, event) => event.data }),
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment