Possibility to extend a machines invoke functions?
Avocher opened this issue · comments
Jonathan Aschan commented
Is there a way to extend machines like in xstate: https://xstate.js.org/docs/guides/machines.html#extending-machines. I would specifically be interested in overriding my invoked functions so i can reuse my machines.
My example use case is a form machines fetching data from different apis that have very different reponse formats.
Matthew Phillips commented
With Robot reuse comes through composition. So I would suggest defining something like:
function formsMachine(fetch) {
return createMachine({
one: invoke(fetch) // ...
})
}
const usersPageMachine = formsMachine(() => fetch('/api/foo'));
const adminPageMachine = formsMachine(() => fetch('/api/bar'));
Jonathan Aschan commented
That will work nicely, thx!