I am currently trying to convert my ngrx store to use ngrx/data to handle my entities. One of the trickier obstacles I have hit is handling API endpoints that return data for multiple entities. A simple example- lets say I have the following models that can be retrieved from my API:
export interface Parent {
id: string;
name: string;
}
export interface Child {
id: string;
name: string;
parent: string
}
And I have the following endpoints:
/api/parents #GET (list of parents), POST (create new parent)
/api/parents/<PARENT_ID> #GET, PATCH, PUSH, DELETE (a single parent)
/api/children #GET (list of children), POST (create new child)
/api/children/<CHILD_ID> #GET, PATCH, PUSH, DELETE (a single child)
/api/families #GET (all parents and children)
/api/families
is a convenience function, that returns all parents and children in the format:
{
parents: Parent[];
children: Child[];
}
In the past, I have made a separate families
entry for my ngrx store with just loading/loaded parameters, then a set of LoadFamilies
actions to grab the data from the server. I then include those actions in my Parents and Children store reducers, and act on them appropriately. What I want to do now is add this additional reducer to my existing ngrx/data controlled entities. Any thoughts/example code on how to go about this?