Suggestion: namespaced reducers / actions
See original GitHub issueHi!
I love redux and I love reducers that filter actions by a namespace and created my own namespaced-duck-factory library because of that.
It seems that redux-toolkit could make my lib obsolete so I would love to have the option of creating state slice reducers that filter actions by a { meta: ‘namespace’ } property (for example).
If I understand it correctly it would be a little extension of createSlice()
so it also emits namespaced action-creators.
Thanks for reading 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Namespacing Actions for Redux - Kickstarter Engineering
When an action is dispatched, each reducer is called with that action and the slice of state which corresponds to its name.
Read more >Redux module composition and how to avoid namespacing
redux-form, react-redux-toastr) The module exposes a function that given a prefix returns already namespaced reducers and actions.
Read more >Redux store namespaced actions? - reactjs - Stack Overflow
Whenever I want to create a new view I can inherit this base view. All possible actions are shared in the reducer. The...
Read more >Namespacing Redux Action Type Constant Values
Namespacing Redux Action Type Constant Values. Most everyone agrees that defining constants for your Redux action types is good idea.
Read more >Namespacing Redux Action Type Constant Values | by Cliff Hall
If your action types are defined in separate files, chances are the reducers that respond to them are as well.
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 Free
Top 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
Sorry to comment such an old thread.
As It turns out. redux-toolkit did indeed made it unneccessary to have preconfigured slices. (I also never really needed the namespacing) Especially with the entityAdapter and immer out of the box.
So this library gave me so much joy and makes my life easier.
I even managed to introducce it to a context / hooks only codebase for a large client and it works very well so far - we use it to make redux-less redux possible (by using it with useReducer() and some middleware)
So thanks and:
Happy Christmas (well, soon-ish) 😄 @phryneas
Heyo 😃
createSlice
already namepaces all actions going with the slice - so anincrement
action on acounter
slice would be of typecounter/increment
.So if you were to namepace that again, I believe it would be more appropriate to namespace the
type
one level deeper (creating types likenamespace/counter/increment
) instead of usingmeta
for that - as reducers usually decide solely bytype
if they’re responsible for handling an action and many established patterns (and interop with many other libraries) break if this rule is ignored.If you wanted to do that, there’s nothing speaking against creating some kind of “higher-order-slice” like this:
So I think your use case should already be covered - would that work for you?
PS: I love the logo of your library - childhood memories!