I'm learning React and Redux by creating an app which contains an array of time-based data: allowed time, and elapsed time.
[1] : {
time: 10,
elapsed: 0
},
[2] : {
time: 15,
elapsed: 0
},
[3] : {
time: 20,
elapsed: 0
}
If any items go over schedule, I want to recalculate the times for subsequent items. E.g. item 1 is allowed 10 seconds, but if item 1 takes 12 seconds I want to make up that time from items 2 and 3.
[1] : {
time: 10,
elapsed: 12
},
[2] : {
time: 14,
elapsed: 0
},
[3] : {
time: 19,
elapsed: 0
}
Where should I perform this calculation? I feel like the easiest place to do this would be the reducer, but I also think that reducers should be as simple as possible? Is that correct?
So should the calculations go in the action-creator, and then a new items array passed to the store?