Today as we are using the API middleware
, we reduced a large amount of code to do something that was implemented differently in many places…
We can do even better by removing many reducers files which do exactly the same:
maintain the API request cycle of Request
, Success
, Failure
.
There are two approaches I’ve been investigating:
- create higher order API reducer which will be consumed in every component’s reducer file.
Every component will have the ability to choose the name of the reducer, create its own selectors etc… - create API reducer which will save all of the API processes under its namespace, e.g:
{
...reducers,
API: {
FACT_CHART: { status, error, results, ...payload },
POWER_STATUS: { status, error, results, ...payload },
}
}
The second option will save the reducer by a unique key
which is already being provided in all of the API requests which are using the API middleware,
without the need to create a reducer by yourself, or a selector.
In both options you could override the default behavior.
Which path in your opinion we should go? I must say that I like the second one as it create things automatically and need less boilerplate, take a look on the draft PRs:
- create higher order API reducer - https://github.com/theforeman/foreman/pull/7217
- create main API reducer - https://github.com/theforeman/foreman/pull/7222