Skip to content

Instantly share code, notes, and snippets.

@benfavre
Last active November 25, 2019 10:03
Show Gist options
  • Save benfavre/e36c1c1b82ef1d23ec995e9fb6767e1e to your computer and use it in GitHub Desktop.
Save benfavre/e36c1c1b82ef1d23ec995e9fb6767e1e 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 validationStates = {
initial: 'waiting',
states: {
waiting: {
on: {
CLIENT_ACCEPTED: {
target: 'acceptedAndReady',
},
CLIENT_CORRECT: 'correctionsPendingAdminAction'
}
},
correctionsPendingAdminAction: {
on: {
ADMIN_CORRECTIONS_DONE: {
target: 'correctionsPendingClientAction',
actions: assign({
corrections: (context, event) => context.corrections + 1
})
},
}
},
correctionsPendingClientAction: {
on: {
CLIENT_CORRECTIONS_DONE: 'acceptedAndReady',
CLIENT_CORRECTIONS_REJECT: 'correctionsPendingAdminAction'
}
},
acceptedAndReady: {}
}
}
const fetchMachine = Machine({
id: 'fetch',
initial: 'unsavedDraft',
context: {
rejected: 0,
corrections: 0
},
states: {
unsavedDraft: {
on: {
SAVE_DRAFT: 'draft'
}
},
draft: {
on: {
SUBMIT_FOR_CREATION: 'pendingAdminApproval',
}
},
pendingAdminApproval: {
on: {
REJECTED: {
target: 'draft',
actions: assign({
rejected: (context, event) => context.rejected + 1
})
},
ACCEPTED: 'readyForClientValidation',
}
},
readyForClientValidation: {
on: {
isValid: 'readyForPayment',
},
...validationStates
},
readyForPayment: {
on: {
payed: 'processable'
}
},
processable: {
on: {
processed: 'deliverable',
},
states: {
processing: {
initial: 'idle',
states: {
idle: {
on: {
INIT_UPLOAD: 'pending'
}
},
pending: {
on: {
UPLOAD_COMPLETE: 'success'
}
},
success: {}
}
},
}
},
deliverable: {
on: {
delivered: 'customerSatisfaction',
},
states: {
delivering: {
initial: 'idle',
states: {
idle: {
on: {
INIT_UPLOAD: 'pending'
}
},
pending: {
on: {
UPLOAD_COMPLETE: 'success'
}
},
success: {}
}
},
}
},
customerSatisfaction: {
initial: 'idle',
states: {
idle: {
on: {
INIT_DOWNLOAD: 'pending'
}
},
pending: {
on: {
DOWNLOAD_COMPLETE: 'success'
}
},
success: {}
}
},
done: {
type: "final"
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment