I have an object in my state like :
I have a property sections, that is an array of objects, I want to add an item in the geometri_linestring array of a specific object in the sections array, to do this, I did this in my reducer :
const setPointSuccess = curry(({ point }, state) => {
const activeTronconId = point.activeTroncon;
let circuit = state.addedCircuit;
let sections = circuit.sections;
let troncon = sections.filter(section => section.tronconId === activeTronconId)[0];
let disabledTroncons = sections.filter(section => section.tronconId !== activeTronconId);
const { latitude, longitude } = point;
let geoLineString = troncon.geometri_linestring;
geoLineString.push({ latitude, longitude });
troncon.geometri_linestring = geoLineString;
disabledTroncons.push(troncon);
sections = disabledTroncons;
circuit.sections = sections;
let addedCircuit = circuit;
return {
...state,
addedCircuit,
};
});
So, I think it is not a good code, it can be better, using ramda expressions, but I can't think of doing this, since I went so deep in that object.
Is there a simpler way to do this ?
Any help would be much appreciated.
