Skip to content

Instantly share code, notes, and snippets.

@MichielDeMey
Last active March 11, 2021 13:34
Show Gist options
  • Save MichielDeMey/0616e2602b6f65266d91ea1984ec74e1 to your computer and use it in GitHub Desktop.
Save MichielDeMey/0616e2602b6f65266d91ea1984ec74e1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const mockPoll = () => {
return new Promise((resolve, reject) => {
console.log('Polling...')
setTimeout(() => {
console.log('Done polling')
return resolve([{
id: 'foo',
name: 'Foo'
}, {
id: 'bar',
name: 'Bar'
}]);
}, 3000);
})
}
const machineActions = {
setEntities: assign({
entities: (context, event) => event.data,
}),
configureNextEntity: assign({
currentEntityIndex: (ctx, event) => {
return ctx.currentEntityIndex + 1;
}
}),
}
const monitrOnboardingMachine = Machine({
id: 'onboarding',
initial: 'check',
strict: true,
states: {
check: {
always: [
{ target: 'importing', cond: (context, event) => context.hasIntegration },
{ target: 'addIntegration' }
]
},
addIntegration: {
on: {
NEXT: 'importing',
},
},
importing: {
on: {
IMPORTED: {
target: 'configureEntitity',
actions: 'setEntities',
},
},
},
configureEntitity: {
initial: 'setupReporting',
states: {
setupReporting: {
on: {
NEXT: 'setupEntity',
},
},
setupEntity: {
on: {
NEXT: '#onboarding.finish',
},
},
},
},
finish: {
type: 'final',
},
},
context: {
hasIntegration: true,
entities: [],
currentEntityIndex: 0,
},
},
{
delays: {},
actions: {
setEntities: assign({
entities: (context, event) => event.data,
}),
configureNextEntity: assign({
currentEntityIndex: (ctx, event) => {
return ctx.currentEntityIndex + 1;
},
}),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment