Skip to content
This repository was archived by the owner on Dec 15, 2018. It is now read-only.

Commit e7badbf

Browse files
author
Ville Saukkonen
committed
rename router.enhancer to router.connect
1 parent 3e530c0 commit e7badbf

11 files changed

+48
-40
lines changed

ADVANCED.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ app.use('/*', (req, res) => {
3737
// routerForExpress will infer the basename
3838
// from req.baseUrl!
3939
//
40-
const { reducer, middleware, enhancer } = routerForExpress({
40+
const { reducer, middleware, connect } = routerForExpress({
4141
routes,
4242
request: req
4343
})
4444

4545
const store = createStore(
4646
combineReducers({ router: reducer }),
4747
{ what: 'ever' },
48-
compose(enhancer, applyMiddleware(middleware))
48+
applyMiddleware(middleware)
4949
);
50+
51+
connect(store);
5052

5153
// ...then renderToString() your components as usual,
5254
// passing your new store to your <Provider> component.
@@ -86,16 +88,18 @@ server.route({
8688
// Create the Redux store, passing in the Hapi
8789
// request to the routerForHapi factory.
8890

89-
const { reducer, middleware, enhancer } = routerForHapi({
91+
const { reducer, middleware, connect } = routerForHapi({
9092
routes,
9193
request
9294
})
9395

9496
const store = createStore(
9597
reducer,
9698
{ what: 'ever' },
97-
compose(enhancer, applyMiddleware(middleware))
99+
applyMiddleware(middleware)
98100
);
101+
102+
connect(store);
99103

100104
// ...then renderToString() your components as usual,
101105
// passing your new store to your <Provider> component.
@@ -125,16 +129,18 @@ const routes = {
125129

126130
const {
127131
reducer,
128-
enhancer,
132+
connect,
129133
middleware
130134
} = routerForBrowser({ routes });
131135

132136
const store = createStore(
133137
combineReducers({ router: reducer }),
134138
window.__INITIAL_STATE,
135-
compose(enhancer, applyMiddleware(middleware))
139+
applyMiddleware(middleware)
136140
);
137141

142+
connect(store);
143+
138144
// ...then render() your components as usual,
139145
// passing your new store to your <Provider> component.
140146
```

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ While React Router is a great, well-supported library, it hoards URL state withi
2828

2929
## Redux usage
3030

31-
To hook into Redux applications, `redux-little-router` uses a store enhancer that wraps the `history` module and adds current and previous router state to your store. The enhancer listens for location changes and dispatches rich actions containing the URL, parameters, and any custom data assigned to the route. `redux-little-router` also adds a middleware that intercepts navigation actions and calls their equivalent method in `history`.
31+
To connect into Redux applications, `redux-little-router` uses a store connector that wraps the `history` module and adds current and previous router state to your store. The connector listens for location changes and dispatches rich actions containing the URL, parameters, and any custom data assigned to the route. `redux-little-router` also adds a middleware that intercepts navigation actions and calls their equivalent method in `history`.
3232

3333
### Wiring up the boilerplate
3434

@@ -72,11 +72,11 @@ const routes = {
7272

7373
// Install the router into the store for a browser-only environment.
7474
// routerForBrowser is a factory method that returns a store
75-
// enhancer and a middleware.
75+
// connect and a middleware.
7676
const {
7777
reducer,
7878
middleware,
79-
enhancer
79+
connect
8080
} = routerForBrowser({
8181
// The configured routes. Required.
8282
routes,
@@ -87,11 +87,13 @@ const {
8787
const clientOnlyStore = createStore(
8888
combineReducers({ router: reducer, yourReducer }),
8989
initialState,
90-
compose(enhancer, applyMiddleware(middleware))
90+
applyMiddleware(middleware)
9191
);
92+
93+
connect(clientOnlyStore);
9294
```
9395

94-
Often, you'll want to update state or trigger side effects after loading the initial URL. To maintain compatibility with other store enhancers (particularly ones that handle side effects, like `redux-loop` or `redux-saga`), we require this optional initial dispatch to happen in client code by doing the following:
96+
Often, you'll want to update state or trigger side effects after loading the initial URL. To maintain compatibility with store enhancers (particularly ones that handle side effects, like `redux-loop` or `redux-saga`), we require this optional initial dispatch to happen in client code by doing the following:
9597

9698
```js
9799
import { initializeCurrentLocation } from 'redux-little-router';
@@ -164,7 +166,7 @@ export const redirect = href => dispatch => {
164166
};
165167
```
166168

167-
On location changes, the store enhancer dispatches a `LOCATION_CHANGED` action that contains at least the following properties:
169+
On location changes, the router connector dispatches a `LOCATION_CHANGED` action that contains at least the following properties:
168170

169171
```js
170172
// For a URL matching /messages/:user

demo/client/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import routes from './routes';
1010
import wrap from './wrap';
1111
import Demo from './demo';
1212

13-
const { reducer, enhancer, middleware } = routerForBrowser({ routes });
13+
const { reducer, connect, middleware } = routerForBrowser({ routes });
1414

1515
const store = createStore(
1616
combineReducers({ router: reducer }),
@@ -22,7 +22,7 @@ const store = createStore(
2222
window.devToolsExtension ? window.devToolsExtension() : f => f
2323
)
2424
);
25-
enhancer(store);
25+
connect(store);
2626
const initialLocation = store.getState().router;
2727
if (initialLocation) {
2828
store.dispatch(initializeCurrentLocation(initialLocation));

demo/server/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ app.get('/*', (req, res) => {
8585
applyMiddleware(router.middleware)
8686
);
8787

88-
router.enhancer(store);
88+
router.connect(store);
8989
const content = renderToString(wrap(store)(Root));
9090

9191
return res.send(

src/enhancer.js renamed to src/connector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { locationDidChange, didReplaceRoutes, replace } from './actions';
1010

1111
import matchCache from './util/match-cache';
1212

13-
type EnhancerArgs = {|
13+
type ConnectorArgs = {|
1414
history: History,
1515
matchRoute: Function,
1616
createMatcher: Function
1717
|};
1818

19-
export default ({ history, matchRoute, createMatcher }: EnhancerArgs) => (
19+
export default ({ history, matchRoute, createMatcher }: ConnectorArgs) => (
2020
store: Store<*, *>
2121
) => {
2222
let currentMatcher = matchRoute;

src/install.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Location } from './types';
44

55
import reducer from './reducer';
66
import middleware from './middleware';
7-
import enhancer from './enhancer';
7+
import connector from './connector';
88

99
import { default as matcherFactory } from './util/create-matcher';
1010
import validateRoutes from './util/validate-routes';
@@ -36,7 +36,7 @@ export default ({
3636
}
3737
}),
3838
middleware: middleware({ history }),
39-
enhancer: enhancer({
39+
connect: connector({
4040
history,
4141
matchRoute,
4242
createMatcher

test/enhancer.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import defaultRoutes from './test-util/fixtures/routes';
1111

1212
chai.use(sinonChai);
1313

14-
describe('Router store enhancer', () => {
14+
describe('Router store connector', () => {
1515
let store;
1616
let historyStub;
1717
let listenStub;
@@ -24,7 +24,7 @@ describe('Router store enhancer', () => {
2424
const replace = sandbox.spy(() => listen(listenStub));
2525
historyStub = { push, replace, listen };
2626

27-
const { reducer, middleware, enhancer } = install({
27+
const { reducer, middleware, connect } = install({
2828
routes: defaultRoutes,
2929
history: historyStub,
3030
location: { pathname: '/' }
@@ -35,7 +35,7 @@ describe('Router store enhancer', () => {
3535
{},
3636
applyMiddleware(middleware)
3737
);
38-
enhancer(store);
38+
connect(store);
3939
sandbox.spy(store, 'dispatch');
4040
});
4141

test/environment/browser-router.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import routes from '../test-util/fixtures/routes';
1010
chai.use(sinonChai);
1111

1212
describe('Browser router', () => {
13-
it('creates a browser store enhancer using history location', () => {
14-
const { enhancer, middleware, reducer } = routerForBrowser({
13+
it('creates a browser store connector using history location', () => {
14+
const { connect, middleware, reducer } = routerForBrowser({
1515
routes,
1616
history: {
1717
location: {
@@ -27,7 +27,7 @@ describe('Browser router', () => {
2727
{},
2828
applyMiddleware(middleware)
2929
);
30-
enhancer(store);
30+
connect(store);
3131
const state = store.getState();
3232
expect(state).to.have.nested.property('router.pathname', '/home');
3333
expect(state).to.have.nested.property('router.search', '?get=schwifty');
@@ -38,7 +38,7 @@ describe('Browser router', () => {
3838
});
3939

4040
it('supports basenames', () => {
41-
const { enhancer, middleware, reducer } = routerForBrowser({
41+
const { connect, middleware, reducer } = routerForBrowser({
4242
routes,
4343
basename: '/cob-planet',
4444
history: {
@@ -55,7 +55,7 @@ describe('Browser router', () => {
5555
{},
5656
applyMiddleware(middleware)
5757
);
58-
enhancer(store);
58+
connect(store);
5959
const state = store.getState();
6060
expect(state).to.have.nested.property('router.basename', '/cob-planet');
6161
expect(state).to.have.nested.property('router.pathname', '/home');

test/environment/express-router.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import routes from '../test-util/fixtures/routes';
1010
chai.use(sinonChai);
1111

1212
describe('Express router', () => {
13-
it('creates a server store enhancer using Express request object', () => {
14-
const { enhancer, middleware, reducer } = routerForExpress({
13+
it('creates a server store connector using Express request object', () => {
14+
const { connect, middleware, reducer } = routerForExpress({
1515
routes,
1616
request: {
1717
path: '/home',
@@ -23,7 +23,7 @@ describe('Express router', () => {
2323
{},
2424
applyMiddleware(middleware)
2525
);
26-
enhancer(store);
26+
connect(store);
2727
const state = store.getState();
2828
expect(state).to.have.nested.property('router.pathname', '/home');
2929
expect(state).to.have.nested.property('router.search', '?get=schwifty');
@@ -33,7 +33,7 @@ describe('Express router', () => {
3333
});
3434

3535
it('supports basenames', () => {
36-
const { enhancer, middleware, reducer } = routerForExpress({
36+
const { connect, middleware, reducer } = routerForExpress({
3737
routes,
3838
request: {
3939
baseUrl: '/cob-planet',
@@ -46,7 +46,7 @@ describe('Express router', () => {
4646
{},
4747
applyMiddleware(middleware)
4848
);
49-
enhancer(store);
49+
connect(store);
5050
const state = store.getState();
5151
expect(state).to.have.nested.property('router.basename', '/cob-planet');
5252
expect(state).to.have.nested.property('router.pathname', '/home');

test/environment/hapi-router.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import routes from '../test-util/fixtures/routes';
1010
chai.use(sinonChai);
1111

1212
describe('Hapi router', () => {
13-
it('creates a server store enhancer using Hapi request object', () => {
14-
const { enhancer, middleware, reducer } = routerForHapi({
13+
it('creates a server store connector using Hapi request object', () => {
14+
const { connect, middleware, reducer } = routerForHapi({
1515
routes,
1616
request: {
1717
path: '/home',
@@ -23,7 +23,7 @@ describe('Hapi router', () => {
2323
{},
2424
applyMiddleware(middleware)
2525
);
26-
enhancer(store);
26+
connect(store);
2727
const state = store.getState();
2828
expect(state).to.have.nested.property('router.pathname', '/home');
2929
expect(state).to.have.nested.property('router.search', '?get=schwifty');

test/environment/hash-router.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import routes from '../test-util/fixtures/routes';
1010
chai.use(sinonChai);
1111

1212
describe('Hash router', () => {
13-
it('creates a browser store enhancer using window.location', () => {
13+
it('creates a browser store connector using window.location', () => {
1414
const history = {
1515
listen() {},
1616
location: {
1717
pathname: '/home',
1818
search: '?get=schwifty'
1919
}
2020
};
21-
const { enhancer, middleware, reducer } = routerForHash({
21+
const { connect, middleware, reducer } = routerForHash({
2222
routes,
2323
history
2424
});
@@ -27,7 +27,7 @@ describe('Hash router', () => {
2727
{},
2828
applyMiddleware(middleware)
2929
);
30-
enhancer(store);
30+
connect(store);
3131
const state = store.getState();
3232
expect(state).to.have.nested.property('router.pathname', '/home');
3333
expect(state).to.have.nested.property('router.search', '?get=schwifty');
@@ -45,7 +45,7 @@ describe('Hash router', () => {
4545
}
4646
};
4747

48-
const { enhancer, middleware, reducer } = routerForHash({
48+
const { connect, middleware, reducer } = routerForHash({
4949
routes,
5050
history,
5151
basename: '/cob-planet'
@@ -55,7 +55,7 @@ describe('Hash router', () => {
5555
{},
5656
applyMiddleware(middleware)
5757
);
58-
enhancer(store);
58+
connect(store);
5959
const state = store.getState();
6060
expect(state).to.have.nested.property('router.basename', '/cob-planet');
6161
expect(state).to.have.nested.property('router.pathname', '/home');

0 commit comments

Comments
 (0)