Open
Description
If I have two action types with different payload
structure I have to describe the types and functions for selecting the data from these action in different places
const todos = map({
addActionTypes: ['ADD_TODO', 'ADD_NOTE_WITH_TODO'],
keyGetter: action => {
if (action.type === 'ADD_NOTE_WITH_TODO') {
return action.payload.note.todo.id;
}
if (action.type === 'ADD_TODO') {
return action.payload.id;
}
},
itemGetter: action => {
if (action.type === 'ADD_NOTE_WITH_TODO') {
return action.payload.note.todo;
}
if (action.type === 'ADD_TODO') {
return action.payload;
}
},
});
That looks pretty bad because we divide describing action type and related logic.
What about describing all related getter methods together with these types?
const todos = map({
addActionTypes: [
{
type: 'ADD_TODO'
},
{
type: 'ADD_NOTE_WITH_TODO',
keyGetter: action => action.payload.note.todo.id,
itemGetter: action => action.payload.note.todo,
},
],
});
Metadata
Assignees
Labels
No labels
Activity