Namespace for reducers
See original GitHub issueSo, you have mentioned that there is available possibility to add namespace for action creators. Like below (for example):
const actionCreators = createActions({
USER: {
CREATE_ITEM: data => ({ data }) ,
DELETE_ITEM: ( ... ) => ...,
GET_LIST: ( ... ) => ...,
...
}
});
But how I can create namespace for reducers, like for such trivial operations as CRUD. Example:
// Creating CRUD reducer template
const crudReducerTemplate = {
CREATE_ITEM: (state, action ) => ...,
DELETE_ITEM: ( ... ) => ...,
GET_LIST: ( ... ) => ...,
...
};
// Creating reducer for users' CRUD operations
const userReducers = handleAction({
USER: {
...crudReducerTemplate
}
}, /* Default state here */);
// Creating reducer for articles' CRUD operations
const articleReducers = handleAction({
ARTICLE: {
...crudReducerTemplate
}
}, /* Default state here */);
Is it possible to do with your utile? Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
Namespacing Actions for Redux
I'll cover why we wanted to namespace our Redux actions, ... With Redux, you can use combineReducers to create nested reducers that only ......
Read more >Namespacing · Redux Subspace - GitHub Pages
To prevent this type of action cross-talk, we can namespace the subspaces and the reducers to filter out actions destined the other sub-application:...
Read more >Namespaces for Redux actions, reducers and state.
Build re-usable components in React, or any other UI library, using Redux adds complexity. Namespacing actions, reducers and state allows multiple instances of ......
Read more >The Secret to Using Redux at Scale | by Kevin Ghadyani
Pretty simple. It let's you tie a namespace to a segment of state. And it really works as if it's a reducer itself....
Read more >using reducer namespace in redux to practice DRY
using reducer namespace in redux to practice DRY ; switch (action.type) ; loading: true ; loading: false ; case "RESET" ; case "DONE_RESET" ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@akomm Thanks again. I’ll try it. Also I’ve found multireducer library. Seems it’s like that I’m want and looking for.
There is a possibility to group reducers as you want using combineReducers from “redux” npm package. The problem is the action identity when you reuse reducers. You also have to duplicate-namespace actions.
Even though often you have “1:1 relation” between action/reducer, by design reducers can act on any action. You could make special factories which could generate what you want. But any approach I image feels to overcomplicated as there are other, easier approaches to solve this problem.
You could turn the whole structure. Instead of namespacing reducers, namespacing actions, adding new keys for generic stuff, I would create a single action set and reducer for generic states and namespace them under the reducer key itself. Check redux-form or apollo-client as an example. redux-form manages all different form states under a single “form” key and namespaces the form states inside via a key (formId) => state.
In your case you would have state { entities: { article: …, user: … }
Even though what you would could be done at first glance, I’m not sure whether it that makes any sense.