Open Romms opened 6 years ago
This idea will be better if keep in mind this issue https://github.com/adrienjt/redux-data-structures/issues/8 what allow us to describe getters only for one action type. Than we can write like that
const todos = map({
addActionTypes: [
{
todo: 'ADD_ONE_TODO',
keyGetter: action => action.payload.uuid,
},
{
todo: 'ADD_FEW_TODOS',
* keyGetter(action) { yield* action.payload.map(todo => todo.uuid); },
* itemGetter(action) { yield* action.payload; },
},
],
});
Those are great suggestions @Romms ! (this and #8)
Getters would not only be specific to action types, but also to "sub-reducers" (add/change/remove). That would make the design more flexible, and we wouldn't have to add confusing parameters like manyItemsGetter
in #6. However, simple use cases might become more verbose.
I'll definitely consider your suggestions for v1. Thank you.
What about an idea to make
getter
methods be a generator function? It can allow us to do this for example:I think it is an easy way to solve the problem described here https://github.com/adrienjt/redux-data-structures/issues/5#issuecomment-362779807