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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/createDispatcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import compose from './utils/composeMiddleware';
import composeMiddleware from './utils/composeMiddleware';

export default function createDispatcher(store, middlewares = []) {
return function dispatcher(initialState, setState) {
Expand All @@ -17,6 +17,6 @@ export default function createDispatcher(store, middlewares = []) {
middlewares = middlewares(getState);
}

return compose(...middlewares, dispatch);
return composeMiddleware(...middlewares, dispatch);
};
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export createRedux from './createRedux';
export createDispatcher from './createDispatcher';

// Utilities
export compose from './utils/composeMiddleware';
export composeMiddleware from './utils/composeMiddleware';
export composeStores from './utils/composeStores';
export bindActionCreators from './utils/bindActionCreators';
2 changes: 1 addition & 1 deletion src/utils/composeMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function compose(...middlewares) {
export default function composeMiddleware(...middlewares) {
return middlewares.reduceRight((composed, m) => m(composed));
}
10 changes: 5 additions & 5 deletions test/compose.spec.js → test/composeMiddleware.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import expect from 'expect';
import { compose } from '../src';
import { composeMiddleware } from '../src';

describe('Utils', () => {
describe('compose', () => {
describe('composeMiddleware', () => {
it('should return combined middleware that executes from left to right', () => {
const a = next => action => next(action + 'a');
const b = next => action => next(action + 'b');
const c = next => action => next(action + 'c');
const dispatch = action => action;

expect(compose(a, b, c, dispatch)('')).toBe('abc');
expect(compose(b, c, a, dispatch)('')).toBe('bca');
expect(compose(c, a, b, dispatch)('')).toBe('cab');
expect(composeMiddleware(a, b, c, dispatch)('')).toBe('abc');
expect(composeMiddleware(b, c, a, dispatch)('')).toBe('bca');
expect(composeMiddleware(c, a, b, dispatch)('')).toBe('cab');
});
});
});