Skip to content

Instantly share code, notes, and snippets.

@blocka
Last active August 12, 2019 04:48
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 blocka/d72ba94ab775eb0080aeb8738f487a03 to your computer and use it in GitHub Desktop.
Save blocka/d72ba94ab775eb0080aeb8738f487a03 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: 'paymentImporter',
initial: 'adjustPayment',
context: {
donorId: null,
department: null,
campaign: null,
subCampaign: null,
date: null,
batch: null,
duplicates: null,
pledges: null
},
states: {
adjustPayment: {
on: {
PAYMENT_ADJUSTED: {
target: 'loadingDupes',
actions: assign({
campaign: (_, e) => e.campaign,
department: (_, e) => e.department,
subCampaign: (_, e) => e.subCampaign,
batch: (_, e) => e.batch
})
},
}
},
loadingDupes: {
invoke: {
id: 'loadDupes',
src: (context, event) => () => [],
onDone: {
target: 'selectHousehold',
actions: assign({ duplicates: (context, event) => event.data })
}
}
},
selectHousehold: {
initial: 'existingOrNew',
on: {
HOUSEHOLD_SELECTED: {
target: 'loadPledges',
actions: assign({
donorId: (_, e) => e.donorId
})
},
BACK: {
target: 'adjustPayment',
actions: assign({
campaign: () => null,
department: () => null,
subCampaign: () => null,
batch: () => null
})
}
},
states: {
existingOrNew: {
on: {
'': [
{ target: 'createNew', cond: 'noPotentialDupes' },
{ target: 'potentialDupes' }
]
}
},
potentialDupes: {
on: {
CREATE_NEW_SELECTED: 'createNew',
}
},
createNew: {
on: {
BACK: 'potentialDupes'
}
}
},
},
loadPledges: {
invoke: {
id: 'loadPledges',
src: (context, event) => () => [],
onDone: {
target: 'selectPledge',
actions: assign({ pledges: (context, event) => event.data })
}
}
},
selectPledge: {
initial: 'existingOrNew',
on: {
BACK: {
target: 'selectHousehold',
actions: assign({
donorId: () => null
})
}
},
states: {
existingOrNew: {
on: {
'': [
{ target: 'existingPledge', cond: 'hasExistingPledges' },
{ target: 'createNew' }
]
}
},
existingPledge: {
on: {
CREATE_NEW_SELECTED: 'createNew'
},
},
createNew: {
on: {
BACK: 'existingPledge'
}
}
}
}
}
}, {
guards: {
hasExistingPledges: () => false,
noPotentialDupes: () => true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment