Skip to content

Instantly share code, notes, and snippets.

@faisalarbain
Created August 24, 2020 04:03
Show Gist options
  • Select an option

  • Save faisalarbain/71d186d8f08382335c898f352684263a to your computer and use it in GitHub Desktop.

Select an option

Save faisalarbain/71d186d8f08382335c898f352684263a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const addExceptance = group => ({
initial: 'pending',
states: {
pending: {
on: {
[`${group}.accept`]: 'accepted',
reject: '#submission'
}
},
accepted: {
type: 'final'
},
},
})
const addSigner = (group) => ({
initial: 'pending',
states: {
pending: {
on: {
[`${group}.sign`]: 'signed'
}
},
signed: {
type: 'final'
}
}
})
const ReciprocalMachine = Machine({
id: 'reciprocal',
context: {
approval: {}
},
initial: 'draft',
states: {
draft: {
on: {
updateApproval: {
target: 'approved',
actions: assign({
approval: (_, event) => event
})
}
}
},
approved: {
initial: 'executionPlanning',
states: {
executionPlanning: {
on: {
planningDone: 'signoffInProgress'
}
},
signoffInProgress: {
type: 'parallel',
states: {
gdom: addSigner('gdom'),
pmu: addSigner('pmu'),
bcs: addSigner('bcs'),
product: addSigner('product'),
bf: addSigner('bf'),
sales: addSigner('sales'),
csm: addSigner('csm'),
},
onDone: 'signedOff'
},
signedOff: {
type: 'final'
}
},
onDone: 'submission'
},
submission: {
id:'submission',
initial: 'pending',
states: {
pending: {
on: {
sofcaReceived: 'pendingSofcaReview',
}
},
pendingSofcaReview: {
type: 'parallel',
states: {
gdom: addExceptance('gdom'),
pmu: addExceptance('pmu'),
},
onDone: 'accepted'
},
accepted: {
type: 'final'
}
},
onDone: 'execution'
},
execution: {
on: {
done: 'completed',
flagDeviation: 'deviated'
}
},
completed: {
type: 'final'
},
deviated: {
on: {
resolved: 'execution',
reapprovalRequired: 'draft'
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment