-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 stores to set custom enhancers (middlewares) #7417
Comments
For simple middleware usage, you may consider referencing the editor store which has a pattern for extending the store with middlewares: https://github.com/WordPress/gutenberg/blob/master/editor/store/middlewares.js |
Thanks for your quick response. I was looking into that example. However I think that requires for you to define Does not have a latest "fix" that is present on latest version of redux. I feel thinks would be more clear if we have something like:
Specially when you have to deal with couple of stores. Also this attaches a bit more with the default definition of |
After some back-and-forth in #8341 and in evaluating Redux framework-level explorations at reduxjs/redux#1702, I'm inclined to close this as "wontfix". With the Redux pull request, I think it's made evident that anything which could be achieved as an enhancer or middleware could be equally implemented on a simple base store exposing only To your point of boilerplate, I don't think this prevents us or anyone else from implementing a more durable In fact, I'm inclined to think it could be as simple as: const reducer = ( state = {}, action ) => state;
const details = { reducer };
const store = registerStore( STORE_NAME, details );
Object.assign( store, composeEnhancers(
applyMiddleware( ...middleware ),
// other store enhancers if any
)( () => store ) ); Let me know what you think. I'm happy to reopen this should be it shown that the current mechanisms are insufficient. |
Thanks for the follow up here @aduth, however I think by allowing a third parameter during the store registration will provide a more a couple of benefits instead of the approach that uses
Overall I think there are ways to work around and apply custom enhancers to the Thanks again for the follow up here, and let me know if you have any questions. I think closing this one for now is good as you guys might be focusing on higher priority stuff so keep on going 🎉 great job so far. |
Looking into a way to extend the implementation for custom stores, specifically to inject custom middlewares it seems like at the moment this is not possible.
I think this is really helpful mechanism for us (as developers) to decrease complexity from store into middleware or stuff like async actions, as having
selctors
andresolvers
does not fill all scenarios to handleREST
actions.I was looking at #692 however that one is related to the store used internally not for the ones created by third party.
Describe the solution you'd like
I think by adding a new parameter to this function:
registerStore
as an array for custom enhancers and forregisterReducer
so this can be set directly when the store is created.As at the moment the stores only have a single enhancer which is the one used to debug (which is great BTW).
But I think having the opportunity to add custom enhancers here would be great.
Describe alternatives you've considered
Happy to collaborate with a PR for this in order to allow the extension of custom stores as well.
Just wanted to drop the ideas in an issue before moving ahead with that.
Please let me know your thoughts on that one.
Thank you!
The text was updated successfully, but these errors were encountered: