Last active
March 11, 2021 13:34
-
-
Save MichielDeMey/0616e2602b6f65266d91ea1984ec74e1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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