-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: "add all" action types for maps #5
Comments
I see your point. Like you said, it's possible to add hundreds of items to a map at once by dispatching many actions. That's exactly what I do. I know it is not the most efficient way, but the performance impact has been negligible in my case, and a little for-loop in the client code isn't a big deal for me. It's kept the map API simple. Now, I could see a situation where you already have an action with several items, which is reduced by another reducer, and you'd like to reduce that same action into a map, without having to dispatch new actions. Are you in that situation? I can't promise that I'll implement this soon, so feel free to submit a PR. It would be greatly appreciated. I'd call it Thank you for using redux-data-structures! |
Well, I'm using redux-promise-middleware for API requests. I get a list of entities on the
I was thinking that Example: const users = map({
addActionTypes: ['CREATE_USER_FULFILLED'],
addManyActionTypes: ['FETCH_USERS_FULFILLED'],
changeActionTypes: ['UPDATE_USER_FULFILLED'],
removeActionTypes: ['DELETE_USER_FULFILLED'],
collectionGetter: action => [...action.payload], // default
collectionItemGetter: item => ({ ...item }), // default
collectionKeyGetter: item => item.id, // default
itemGetter: action => ({ ...action.payload }), // default
itemModifier: (item, action) => ({ ...item, ...action.payload }), // default
keyGetter: action => action.payload.id, // default
}); I'll submit a PR for this when I have time. |
@adrienjt What do you think about changing |
Let's create an |
I had the same issue: I solved it by using the Codeimport { map } from "redux-data-structures";
import reduceReducers from "reduce-reducers";
const reducer = reduceReducers(map({...}), replaceAllReducer, addAllReducer, removeAllReducer); By doing this, the "all" reducers inherit the state shape from It's a workaround, but it works for the time being. |
Right now there is no simple way to add multiple items at once to a map. We have to dispatch an add action for each element when we want to add a list of items.
It would be nice to have a
addAllActionTypes
option that would iterate on the action's payload and add all items. This could also need acollectionGetter
option.For lists, since you're using
Array.prototype.concat
, the add actions work for adding both single and multiple items.The text was updated successfully, but these errors were encountered: