dimanche 5 janvier 2020

How to architect a react-redux app with grpc-web?

I have a react-redux app and my team uses grpc-web. I'm wondering - what's the best way to design such system?

For now the plan is to create 3 abstraction levels:

  1. API module - promisified wrappers around grpc-web clients
  2. Redux thunks level - async action creators that deal with the API
  3. React components props - will ask for only what component needs

So components know nothing about grpc, they mess with action creators, action creators know nothing about grpc, they deal with an api module, and only api module uses with grpc-web stubbs.

Reasons why I want to go this way:

  • No grpc-specific code in action creators and components
  • My Promise-based API instead of a callback-based API of grpc-web

My questions are:

  1. Is it a good idea to have an abstraction level between Redux and grpc-web? Or it's better to keep that stuff inside action creators logic?
  2. Is there a common design pattern I should think of? (I am thinking about "Adapter")
  3. Is it a good idea to promisify grpc-web API? If yes, is it a good idea to write a function and do it on the fly?
  4. Can I say that my current plan is Adapter Pattern?
  5. If I want to use an Adapter Pattern, am I have to map every element of data collection to my interface? I now that my components and, maybe, action-creators, should now depend on grpc-web API because it's backend API and it may change

Aucun commentaire:

Enregistrer un commentaire