Skip to content

Instantly share code, notes, and snippets.

@pckilgore
Created July 13, 2021 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pckilgore/2147d0eeec4ab4aef65bf478dfa9d980 to your computer and use it in GitHub Desktop.
Save pckilgore/2147d0eeec4ab4aef65bf478dfa9d980 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine(
{
id: 'load-and-dedupe-draft-rx-for-entry',
context: {},
initial: 'load_draft_details',
states: {
load_draft_details: {
invoke: {
src: 'getDraftRxDetails'
},
on: {
DRAFT_LOADED: {
target: 'check_rx_draft_is_escribe',
actions: assign({
draftRx: (_ctx, event) => event.draftRx
})
},
ERROR: {
target: 'error'
}
}
},
check_rx_draft_is_escribe: {
invoke: {
src: 'isRxDraftEscribe'
},
on: {
IS_ESCRIBE: {
target: 'load_message_details'
},
IS_NOT_ESCRIBE: {
target: 'should_enter'
}
}
},
load_message_details: {
invoke: {
src: 'getEscribeMessageDetail'
},
on: {
ESCRIBE_DETAILS_LOADED: {
target: 'check_for_duplicate_entry'
},
ERROR: {
target: 'error'
}
}
},
check_for_duplicate_entry: {
invoke: {
src: 'checkForDuplicate'
},
on: {
IS_DUPLICATE: {
target: 'mark_as_duplicate'
},
IS_NOT_DUPLICATE: {
target: 'should_enter'
}
}
},
mark_as_duplicate: {
invoke: {
src: 'markDuplicate'
},
on: {
MARKED_DUPLICATE: {
target: 'is_duplicate_escribe'
},
ERROR: {
target: 'error'
}
}
},
is_duplicate_escribe: {
type: 'final',
data: {
skipped: true,
error: null
}
},
should_enter: {
type: 'final',
data: {
skipped: false,
error: null
}
},
error: {
type: 'final',
data: {
skipped: false,
error: (_ctx, event) =>
event.type === 'ERROR'
? event.error
: Error('Bad Error event')
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment