-
Notifications
You must be signed in to change notification settings - Fork 195
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
Allowing types
to be passed as an object
#72
Comments
Hey Josh! If you're building your own api wrapper see #65 You can easily wrap this yourself and never have to look at it again :) Otherwise, building it into should be straight forward :) |
Hi Peter! That is totally a worthwhile solution, but I'm wondering if it makes sense to be built in for others, like me, for whom it would be intuitive and who don't want to fuss with wrappers. I'm happy either way. Depends on whether you guys think it's worth the extra bit of logic or not :) |
While this can be achieved on user land, I think there is no need to add this into the library, because features that can be achieved on user land, make the library more harder to maintain, for each user that request a feature. 🙂 import { createAction } from 'redux-api-middleware'
function customRSAA(apiCall) {
const { types, ...rest } = apiCall
const { request, success, failure } = types
return createAction({
...rest,
types: [request, success, failure]
})
}
const action = customRSAA({
endpoint: 'http://www.example.com/api/users',
method: 'GET',
types: {
request: 'CATS_REQUEST',
success: 'CATS_RESPONSE',
failure: 'CATS_ERROR'
}
})
store.dispatch(action) |
Just started using redux-api-middleware; really well-thought-out!
A part of the API I don't love is the necessity for
types
to be a 3-value array. It isn't immediately clear that the order is what distinguishes them, as opposed to a specific naming convention. I'd much rather be able to pass an object, like:Would be happy to take a shot at a PR if this is deemed to be a worthwhile addition :)
The text was updated successfully, but these errors were encountered: