-
Notifications
You must be signed in to change notification settings - Fork 67
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
Advanced middleware feature #23
Advanced middleware feature #23
Conversation
Codecov Report
@@ Coverage Diff @@
## master #23 +/- ##
==========================================
+ Coverage 90.14% 92.41% +2.27%
==========================================
Files 7 9 +2
Lines 213 211 -2
==========================================
+ Hits 192 195 +3
+ Misses 21 16 -5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamlacroix Thanks for taking the time to pull this together. I have a few comments. Let me know what you think.
src/adapters/superagent.js
Outdated
import superagent from 'superagent'; | ||
import * as httpMethods from '../constants/http-methods'; | ||
|
||
export const __createRequest = (url, method) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to indicate that it shouldn't be used except by tests? If so I think it's fine to just export it without the __
prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that's all it meant, I'll remove it.
src/middleware/query-advanced.js
Outdated
|
||
const resOk = (status) => Math.floor(status / 100) === 2; | ||
|
||
const queryMiddlewareAdvanced = (queriesSelector, entitiesSelector, networkAdapter, config = defaultConfig) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pull networkAdapter
out like so:
const queryMiddlewareAdvanced = (networkAdapter) => (queriesSelector, entitiesSelector, config = defaultConfig)
Then the default middleware will be much simpler:
const queryMiddleware = queryAdvanced(superagentAdapter);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ That's a much better idea.
src/index.js
Outdated
@@ -8,5 +8,6 @@ export { default as getQueryKey } from './lib/get-query-key'; | |||
export { default as queriesReducer } from './reducers/queries'; | |||
export { default as entitiesReducer } from './reducers/entities'; | |||
export { default as queryMiddleware } from './middleware/query'; | |||
export { default as queryMiddlewareAdvanced } from './middleware/query-advanced'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I see with this is that projects that use the new queryMiddlewareAdvanced
will keep pulling in superagent
through the queryMiddleware
from above.
I'm thinking we can easily fix this by:
- duplicating
src/index.js
to a new filesrc/advanced.js
- removing the
'./middleware/query'
import insrc/advanced.js
- removing the
'./middleware/query-advanced'
import insrc/index.js
(to distinguish the different entries and usages) - add a file to the root of the project (
advanced.js
) that is a CommonJS alias todist/commonjs/advanced
This is sort of brittle because a single import for regular redux-query
will cause the app's bundler to start including superagent, but I think it's acceptable for now. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally I think we can modify the webpack config to export a new UMD build for redux-query/advanced
.
@ryanashcraft Thanks for your feedback! I've updated the PR accordingly. Are the UMD changes I made what you had in mind? If not, I'll be happy to update it. |
This moves most of the logic from the query middleware to the new advanced middleware. The query middleware will call advanced using the default superagent adapter.
09b08c9
to
ae29cf4
Compare
@iamlacroix Sorry I botched a minor change (ae29cf4) I added to this PR and had to do a force push. The UMD builds look good. I'm ready to merge this. Before I do, can you do some testing with your app to make sure the advanced entry point and custom adapters works as expected? Also, if you can update add some info in the README that'd be awesome. Thanks! |
@ryanashcraft Great to hear! I'll update the README and let you know the results of testing as soon as I can. |
Can we add support for |
@iamlacroix Do you mind if I help out with this PR to get it merged? I actually need the advanced middleware for a project I have in mind. 😊 |
@ryanashcraft Yea, absolutely. Sorry for the delay on my end, I was sick for a bit and have been getting caught up on work. |
…edux-query into iamlacroix-advanced-middleware
…roix-advanced-middleware
Sorry to write here but I didn't know where to ask. I've recently developed an adapter for I was wondering if this is something you'd like to add to this project (as an alternative to the SuperAngent adapter), or it would better fit its own separate package. |
@acontreras89 Nice! I think for now it makes more sense to have it as a separate package. |
This is the advanced middleware implementation per our discussion in #4.
It moves the built-in superagent request object into an adapter and that adapter is used by default importing the standard
queryMiddleware
. A newqueryMiddlewareAdvanced
export is available which requires an adapter as one of the parameters.The adapter and it's initializer look like this:
Once/if all this is close to being merged, I can update the documentation in the README as well (for advanced usage, normal usage remains the same).