Similiar to setOne and updateOne, it would be useful with a mapOne for cases where you want to update a single entity but the new value depends on the old. Example:
return adapter.mapOne(id, entity => {
...entity,
counter: entity.counter + 1
}, state);
The naming of map would then be a bit inconsistent, but that might be fine. For full consistency the naming would mapOne and mapAll (mapMany could also be added for completeness).
Describe any alternatives/workarounds you're currently using
The same thing can be accomplished by accessing the old entity with state.entities, but it becomes a bit more verbose if you also want to check for existence:
const entity = state.entities[id];
if (entity) {
return state.updateOne({
id,
changes: {
counter: entity.counter + 1
}
})
} else {
return state;
}
If accepted, I would be willing to submit a PR for this feature
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
Similiar to
setOneandupdateOne, it would be useful with amapOnefor cases where you want to update a single entity but the new value depends on the old. Example:The naming of
mapwould then be a bit inconsistent, but that might be fine. For full consistency the naming wouldmapOneandmapAll(mapManycould also be added for completeness).Describe any alternatives/workarounds you're currently using
The same thing can be accomplished by accessing the old entity with
state.entities, but it becomes a bit more verbose if you also want to check for existence:If accepted, I would be willing to submit a PR for this feature
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No