I'm building something with Angular and using redux.
My json object has objects that have certain values. Lets pretend:
name: "john",
sex: "m"
children: [
{
name: "joe",
sex: "m"
children: [
{
name: "mary",
sex: "f"
children: [
{
name: "ryan",
sex: "m"
children: []
}
]
}
]
],
name: "sue",
sex: "f"
children: [
{
name: "joe",
sex: "m"
children: [
{
name: "mary",
sex: "f"
children: [
{
name: "ryan",
sex: "m"
children: []
}
]
}
]
]
Lets say I want to:
- count the amount of total children and grandchildren that john has.
- count the number of grandchildren that john has.
Well then:
- Where would I write the function for this when using Angular/Redux? Would I do it before I get my state? After I make my API call and get my state? In the reducer? In the component?
- What is the fastest/best way to iterate and get those 2 counts that I wanted? Because I know Angular has some built in things, would it have any faster way to do this? Or through plain JS?
And last point:
- Lets say I have some sibling component (john's wife, sue) that will be using this similar count or information. If I want to keep my code DRY, where should I be making these count functions?
Do I use my state from before if some information count is going to be different? Lets say this is only counting female children/granddaughters. And john's is for male children/grandsons.
Or should I be making two slice of state for these (m & f) and working off those?
File Structure:
app
|store
|actions
|models
|reducers
|effects
|views
|john
|.html
|.ts
|sue
|.html
|.ts
|app.ts etc