I'm looking for some help understanding Volto Actions and Reducers more in-depth. I would really appreciate any general links to documentation or tips, as well as specific answers to my questions below!
Looking at the plone training page about Volto actions (47. Volto Actions and Component State โ Mastering Plone 6 Development โ Plone Training 2022 documentation) I understand that you can simply construct an Action object with a type
and details about a request
:
export function getVotes(url) {
return {
type: GET_VOTES,
request: {
op: 'get',
path: `${url}/@votes`,
},
};
}
When this is dispatched, something is watching for it, makes the request, and then eventually dispatches other actions with type
s like GET_VOTES_PENDING
, GET_VOTES_SUCCESS
, GET_VOTES_FAIL
.
My first questions are: What is the something that turns request actions into data? Is it a special reducer? Some kind of side-effect handler? Can I ask it to make complicated requests, multiple requests, etc?
In my case I will need to fetch data about instances of a content type that "contains" many other instances of other content types. To fit with the example above, suppose I am building an overview page where I will see a list of elections that have happened over time. I have a plone folder containing all the elections and I make an action getElections
which returns them as a list. Now I need to make requests for each election returned in order to get the votes that happened in that election.
I understand that there is a query parameter fullobjects=1
which can help remove the need for these extra requests, but in this case fullobjects would still not return enough.
I also understand that in most cases it would make sense to implement a single backend endpoint which gathers all the data needed.
But I would like to understand how best to accomplish this using Volto actions and reducers.
So my second set of questions: Is there a Volto-way of chaining multiple actions / requests together? If not, is there a pattern or library anyone would recommend for implementing this elegantly? I have a couple of hacky solutions, but I'm starting to think I should research packages like redux-loop which seem to solve the problem more generally... has anyone tried redux-loop already?
Thanks so much for reading this long post!