Skip to content

Instantly share code, notes, and snippets.

@laurazenc
Created June 14, 2022 11:05
Show Gist options
  • Select an option

  • Save laurazenc/b628a7cc2ee84e1fa79d6ab73146748f to your computer and use it in GitHub Desktop.

Select an option

Save laurazenc/b628a7cc2ee84e1fa79d6ab73146748f to your computer and use it in GitHub Desktop.

Revisions

  1. laurazenc created this gist Jun 14, 2022.
    54 changes: 54 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'claimsMachine',
    initial: 'idle',
    context: { created: [], failed: [], selected: [] },
    states: {
    idle: {
    on: {
    BULK: 'bulk',
    },
    },
    bulk: {
    initial: 'loading',
    states: {
    idle: {
    on: {
    BULK: 'loading',
    },
    },
    loading: {
    invoke: {
    src: 'bulkClaims',
    onDone: {
    target: 'success',
    actions: 'setData',
    },
    onError: {
    target: 'idle',
    actions: 'setError',
    },
    },
    },
    success: {
    on: {
    BULK: 'loading',
    },
    entry: 'showNotification',
    },
    },
    },
    },
    });