Skip to content

Instantly share code, notes, and snippets.

@jstoppa
Last active April 1, 2020 22:09
Show Gist options
  • Save jstoppa/df0f95fe7f1c4746a523f4b9db0c4b77 to your computer and use it in GitHub Desktop.
Save jstoppa/df0f95fe7f1c4746a523f4b9db0c4b77 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 moveState = stateId =>
fetch(`https://jsonplaceholder.typicode.com/todos/${stateId}`).then(response => response.json());
const fetchMachine = Machine({
id: 'prospectProcess',
initial: 'initial_meeting',
context: {
retries: 0
},
states: {
initial_meeting: {
on: {
NEXT: {
target: 'capture_kyc',
actions: (context, event) => moveState(1)
}
}
},
capture_kyc: {
on: {
COMPLETED: {
target: 'run_complaince_checks',
actions: (context, event) => moveState(2)
},
LOST: {
target: 'lost',
actions: (context, event) => moveState(2)
}
}
},
lost: {
type: 'final'
},
run_complaince_checks: {
on: {
NORMAL: {
target: 'select_products',
actions: (context, event) => moveState(3)
},
PEP: {
target: 'pep_checks',
actions: (context, event) => moveState(4)
}
}
},
pep_checks: {
type: 'parallel',
states: {
check1: {
initial: 'notify_fca',
states: {
notify_fca: {
on: {
NEXT1: {
target: 'done1',
actions: (context, event) => moveState(5)
}
}
},
done1: {
type: 'final'
}
}
},
check2: {
initial: 'get_signed_client_authorisation',
states: {
get_signed_client_authorisation: {
on: {
NEXT2: {
target: 'done2',
actions: (context, event) => moveState(6)
}
}
},
done2: {
type: 'final'
}
}
}
},
onDone: '#prospectProcess.select_products'
},
select_products: {
on: {
NEXT: {
target: 'qa_approval',
actions: (context, event) => moveState(7)
}
}
},
qa_approval: {
on: {
APPROVE: {
target: 'create_alert',
actions: (context, event) => moveState(8)
},
REJECT: {
target: 'open_form',
actions: (context, event) => moveState(9)
}
}
},
open_form: {
on: {
NEXT: {
target: 'select_products',
actions: (context, event) => moveState(10)
}
}
},
create_alert: {
on: {
NEXT: {
target: 'open_products',
actions: (context, event) => moveState(11)
}
}
},
open_products: {
on: {
NEXT: {
target: 'fund_products',
actions: (context, event) => moveState(12)
}
}
},
fund_products : {
on: {
NEXT: {
target: 'won',
actions: (context, event) => moveState(13)
}
}
},
won: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment