-
Notifications
You must be signed in to change notification settings - Fork 188
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
Allow custom separators for action types #165
Comments
You can use type to reducer https://github.com/tomatau/type-to-reducer to handle nested actions. Your structure would suggest namespaces as well as separators e.g. |
const reducer = handleActions({
customer: {
bills: {
add_invoice: {
PENDING: ...,
...
},
},
},
}) |
What's the benefit over using multiple reducers keyed by a namespace variable in conjunction with combineReducers from redux?
You can also do |
I don't see how this is relevant to the issue. Perhaps I didn't understand you, could you please provide a code snippet? Here's what I'm looking for: import { combineReducers } from 'redux'
import { createActions, handleActions } from 'redux-actions'
const actions = createActions({
foo: {
fetch: () => {
return axios.get('/foo')
}
},
bar: {
fetch: () => {
return axios.get('/bar')
}
}
})
const reducer = combineReducers({
foo: handleActions({
fetch: {
PENDING: (state, action) => {...},
FULFILLED: (state, action) => {...},
REJECTED: (state, action) => {...},
}
}),
bar: handleActions({
fetch: {
PENDING: (state, action) => {...},
FULFILLED: (state, action) => {...},
REJECTED: (state, action) => {...},
}
}),
}) However until separators are hardcoded I can't do that. Instead I have to change reducer to following: const reducer = combineReducers({
foo: handleActions({
fetch_PENDING: (state, action) => {...},
fetch_FULFILLED: (state, action) => {...},
fetch_REJECTED: (state, action) => {...},
}),
bar: handleActions({
fetch_PENDING: (state, action) => {...},
fetch_FULFILLED: (state, action) => {...},
fetch_REJECTED: (state, action) => {...},
}),
}) |
I'd suggest using explicit coupling between action creators and reducers based on constants rather than implicit coupling based on object shape and library magic. But I can understand a little benefit to your suggestion. Let's wait for @pburtchaell to share his thoughts on this |
@pburtchaell ping |
I agree with @tomatau that explicit coupling of action creators and reducers is better and that it's best to avoid (magical 🦄 ) libraries like Redux Action, but that's my personal preference. I'd honestly rather not add another config option to the middleware (can potentially bloat the codebase), but I understand your case, @roboslone, and it's a reasonable 3 line diff. I think we can merge this in once the PR is approved. Just add tests, please. 👍 |
Released as |
This is a feature request, so it doesn't fit any template =/
I use
redux-actions
with nested structure to create reducers, like so:With code above action with type
search/setQuery
will be processed by given reducer.However, I cannot use such nested structure for actions dispatched by
redux-promise-middleware
since separator is hardcoded.So I would like to change separator from
_
to/
and use nested structure inhandleActions
:The text was updated successfully, but these errors were encountered: