-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Revised middleware-declaration function's interface #784
Conversation
Updated middleware tests to include 2 args declaration func (among the 1 arg "thunk" interface).
What would the migration process be like? Shall we add warnings for every middleware using the old signature? Shall we support both? Which one would be referenced in the documentation? |
I can't see how the current signature serves the author, I suggest the following migration steps:
Migration is always a sticky business, but I think this should keep us safe. |
How do we show deprecation message if we don't know the name of the offending middleware? |
Good Point. We probably can't name it (not in a practical and satisfactory way anyhow), but we can provide a useful hint: The ordinal of the incompatible function. We can provide warning messages in the line of: `The ${index}${[["st", "nd", "rd"][index-1] || "th"].join('')} middleware factory function used to invoke 'applyMiddleware' is incompatible with the required signature...`; Here's one way in which we can slip this message in: chain = middlewares.map((middleware, index) => middleware.length === 2 ? middleware.bind(undefined, middlewareAPI) : ((middleware)=>{ console.warn(`The...`); return middleware; })(middleware(middlewareAPI))); What do you think? |
I see zero advantage in changing the signature, other than personal dislike of currying. |
I personally love FP along with everything if offers, including the currying technique and monads, so I'm "off the hook" here 😄 In our case though, it might not be the ideal choice since (IMHO):
|
I think we won't do this unless there are other useful breaking changes to middleware. I can't justify changing the signature and causing dozens of maintainers to release new major versions and then responding to incompatibility issues with previous Redux versions because they didn't enforce peer dependencies or such—and all for their apparent convenience. If we planned to change middleware significantly I'd get this in, but at the moment we don't. I understand this keeps the friction, but it's almost moot with ES6 which is what people in Redux ecosystem usually write new code in anyway. Sorry! |
My pleasure 👍 |
The current middleware declaration function is required to return a function to intercept the first two dependencies used to construct the middleware (curry).
Since the actual middleware construction requires "store" (or its simulated API) and "next" (next middleware's "dispatch") to both be available at the time of the middleware's function declaration, and since they're both available right at the time of "applyMiddleware"'s invocation, there is essentially no need to split the two arguments into different function calls.
This PR includes support for both 2 and 1 (for existing middleware) arguments definition funcs:
const myMiddleWare = store => next => action => next(action)
or
const myMiddleWare = (store, next) => action => next(action)
more friendly towards ES5 newcomers (and Express middleware authors):
I believe this minor change could promote authors' familiarity and understanding, thus encourage the development of additional middleware to Redux.