I'm trying to wrap my head around Ramda.js but I'm stuck. I have an array that looks something like this:
const state = [
{
itemId: 112,
animations: [{id: 1}, {id:2}],
classes: ['animated']
},
{
itemId: 121,
animations: [{id:2}],
classes: ['animated']
}
]
My goal is to create a function where
removeAnimation(121, 2, state);
...would return:
const state = [
{
itemId: 112,
animations: [{id: 1}, {id:2}],
classes: ['animated']
},
{
itemId: 121,
animations: [],
classes: []
}
]
So the function removes the animation obj based on the specified id inside the object with the specified itemId, and if no more objects present in the animations array, it also removes the animated string in the classes list.
This is how far I got:
const removeAnimationFromItem = R.curry((itemId, animId, state) => {
return R.map(
R.when(
R.propEq('itemId', itemId), [--This is where I'm stuck--]
), state)
})
Thank you for your time.