Skip to content

Export default middlewares and use consistent naming #79

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

Merged
merged 1 commit into from
Jun 13, 2015

Conversation

emmenko
Copy link
Contributor

@emmenko emmenko commented Jun 13, 2015

To be consistent with e.g.: composeStores.

Also exporting the default thunk middleware is useful if I need to create a dispatcher with other middlewares, for example:

import { createDispatcher, composeStores, middlewares } = 'redux';
import loggerMiddleware from './middlewares/logger';
import * as stores from './stores';

const dispatcher = createDispatcher(
  composeStores(stores),
  getState => [middlewares.thunk(getState), loggerMiddleware(getState)]
);

Does it make sense?

@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

I'd rather not export “middlewares” because it leaves the impression that Redux plans to include many different middlewares (when in fact the opposite is true: we only ship with thunk middleware).

I agree about compose => composeMiddlewares though. It's too generic right now. I understand it's just functional composition, but I think we still need to clarify the intent.

On a sidenote, would composeMiddleware be a better name English-wise?

@acdlite
Copy link
Collaborator

acdlite commented Jun 13, 2015

👍 for renaming to composeMiddleware and leaving off the 's'.

@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

👍 for renaming to composeMiddleware and leaving off the 's'.

If we do that, let's change “middlewares” parameter name inside createDispatcher and composeMiddleware as well.

@acdlite
Copy link
Collaborator

acdlite commented Jun 13, 2015

If we do that, let's change “middlewares” parameter name inside createDispatcher and composeMiddleware as well.

I think the 's' is useful there to clarify that it's an array, not a single middleware.

@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

Good point. Let's do this then:

  • Keep the parameter name middlewares
  • Change the function to be composeMiddleware
  • Keep thunk in ./middleware and don't export it

@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

Since there will be only one default middleware, how about just exporting it as defaultMiddleware?

The only reason for exporting it is to avoid doing import thunk from 'redux/lib/middleware/thunk. Imports should not rely on internal structure...

@acdlite
Copy link
Collaborator

acdlite commented Jun 13, 2015

I don't think redux/middleware/thunk would be so bad. The alternative is to publish it separately on npm, which... I dunno, feels like overkill for a 10 line function :D

@acdlite
Copy link
Collaborator

acdlite commented Jun 13, 2015

Also I don't like defaultMiddleware because it doesn't describe what it actually does.

@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

Right...I don't know, I'm just trying to make it easier to just re-use this middleware instead of copy-paste it.

How about instead having a addMiddleware in the dispatcher? So if I'm happy with the default dispatcher (with thunk middleware) I'll keep it and just add other middlewares. If I want something completely custom, then I just create my own middleware...

@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

How about instead having a addMiddleware in the dispatcher?

But then you'd need clearMiddleware to also delete the default one? What we have now sounds much simpler to me.

I'm just trying to make it easier to just re-use this middleware instead of copy-paste it.

I think it's easy enough to be honest. You either need thunk middleware (and in this case it's good to understand what thunk means anyway because you're going to try composing it with something else), or you don't need it.

@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

Ok, let's keep it like this for now. If there is actually a need we can re-discuss it.

Should I just do the renaming then?

@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

Yeah, please do!

@emmenko emmenko force-pushed the consistent-naming branch from 5e63d83 to dcc9b97 Compare June 13, 2015 21:54
@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

@gaearon done, I also squashed the commits.

@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

Damn it, there is a typo...1sec

@emmenko emmenko force-pushed the consistent-naming branch from dcc9b97 to 3d21465 Compare June 13, 2015 21:56
@emmenko
Copy link
Contributor Author

emmenko commented Jun 13, 2015

Now it should be ok

gaearon added a commit that referenced this pull request Jun 13, 2015
Export default middlewares and use consistent naming
@gaearon gaearon merged commit 5073538 into reduxjs:master Jun 13, 2015
@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

👍 thanks!

@emmenko emmenko deleted the consistent-naming branch June 13, 2015 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants