DEV Community

Discussion on: XState: Why I Love Invoked Callbacks

Collapse
noriste profile image
Stefano Magni

Hey Matt, replacing ALL the services with invoked callbacks (even a simple fetch that returns a promise) has only one "weak" point: testing. If I'm correct, mocking services is handy with withConfig, while for callbacks I must mock the imported and consumed module, right?
So told: I know that callbacks have superior Typescript experience and it's all about the trade-offs 😊
And thanks, I love the clarity of your articles

Collapse
mpocock1 profile image
Matt Pocock Author

You can mock invoked callbacks in exactly the same way as with services! Use a named service and then mock it in the same way.

Collapse
mpocock1 profile image
Matt Pocock Author

See the 'Event Listeners' example

Thread Thread
noriste profile image
Stefano Magni

My bad, sorry 🙏 thanks Matt!