Immutable.js Deletein Not Working
I have been trying to solve this problem, but there is probably something of Immutable.js that I don't catch. I hope somebody can help me to understand. I have a test like this: i
Solution 1:
This should work:
export function removeAtListOfMembers(state) {
const members = state.get('members');
const removing = state.get('removing');
return state
.deleteIn(['members', String(removing) ])
.remove('removing');
}
Your code has two issues:
deleteIn
takes a singlekeyPath
argument, which in your case is[ 'members' ]
. The second argument (removing
) is ignored, so the result is that the entiremembers
map is deleted; instead,removing
should become part of the key path.removing
is aNumber
, but because you're creating aMap
from a JS object, its keys will beString
's (this is mentioned in the documentation as well):Keep in mind, when using JS objects to construct Immutable Maps, that JavaScript Object properties are always strings
So you need to convert removing
to a String
when passing it to deleteIn
.
Post a Comment for "Immutable.js Deletein Not Working"