Hacker News new | ask | show | jobs
by adamkl 2327 days ago
This sounds very similar to what we've been doing with XState[1] and React.

We have a "service layer" for React made up of state-machine-based services (although reactive services based on RxJS observables works as well). We also created associated custom hooks that allow developers to easily "inject" a service into their React component (use use React's Context API for our "DI container"). From there they can read the service state, or send events to it to trigger behaviour that is encapsulated in the service itself.

We even have the same "most used" service; a UserSession service manages OAuth based login flow and session management.

The best part of this approach is that our service layer started in an Angular based proof-of-concept before we lifted-and-shifted it all into React.

[1] https://xstate.js.org/

1 comments

How much does the react wrapper do? Ie how easy would it be to support Angular or Vue? I imagine just aligning syntactic conventions?
React wrapper doesn’t do much, and it is very easy to port to other UI frameworks.

Here’s a follow-up post with a gist of what the React integration looks like.

https://news.ycombinator.com/item?id=22294087