Skip to content

Commit 581f424

Browse files
committed
Container -> Injector, @container -> @Inject, Root -> Dispatcher, @root -> @dispatch
1 parent 0a9cb0d commit 581f424

File tree

11 files changed

+52
-50
lines changed

11 files changed

+52
-50
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ export default class Counter {
136136

137137
```js
138138
// The smart component may inject actions
139-
// and observe stores using <Container />:
139+
// and observe stores using <Injector />:
140140

141141
import React, { Component } from 'react';
142-
import { Root, Container } from 'redux';
142+
import { Injector } from 'redux';
143143
import * as CounterActions from './actions/CounterActions';
144144
import counterStore from './stores/counterStore';
145145
import Counter from './Counter';
@@ -149,11 +149,11 @@ export default class CounterContainer {
149149
// stores and actions must both be string -> function maps.
150150
// props passed to children will combine these actions and state.
151151
return (
152-
<Container stores={{ counter: stores.counterStore }}
152+
<Injector stores={{ counter: stores.counterStore }}
153153
actions={CounterActions}>
154154
{/* Yes this is a function as a child. Bear with me. */}
155155
{({ state, actions }) => <Counter {...state} {...actions} />}
156-
</Container>
156+
</Injector>
157157
);
158158
}
159159
}
@@ -167,10 +167,10 @@ They work exactly the same as the container components, but are lowercase:
167167
```js
168168
import React, { PropTypes } from 'react';
169169
import * as CounterActions from './actions/CounterActions';
170-
import { container } from 'redux';
170+
import { inject } from 'redux';
171171
import counterStore from './stores/counterStore';
172172

173-
@container({
173+
@inject({
174174
actions: CounterActions,
175175
stores: { counter: counterStore }
176176
})
@@ -198,13 +198,15 @@ export default class Counter {
198198

199199
#### The root component
200200

201+
Decorate your top-level component with `@dispatch(stores)` (or `<Dispatcher stores={stores}>` inside) to bind it to a Redux dispatcher instance.
202+
201203
```js
202204
import React from 'react';
203-
import { root } from 'redux';
205+
import { dispatch } from 'redux';
204206
import * as stores from './stores/index';
205207

206208
// Let it know about all the stores
207-
@root(stores)
209+
@dispatch(stores)
208210
export default class App {
209211
/* ... */
210212
}

examples/counter/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import React, { Component } from 'react';
2-
import { root, Container } from 'redux';
2+
import { dispatch, Injector } from 'redux';
33
import { increment, decrement } from './actions/CounterActions';
44
import * as stores from './stores/index';
55
import Counter from './Counter';
66

7-
@root(stores)
7+
@dispatch(stores)
88
export default class CounterApp extends Component {
99
render() {
1010
return (
11-
<Container stores={{ counter: stores.counterStore }}
12-
actions={{ increment, decrement }}>
11+
<Injector stores={{ counter: stores.counterStore }}
12+
actions={{ increment, decrement }}>
1313
{({ state, actions }) => <Counter {...state} {...actions} />}
14-
</Container>
14+
</Injector>
1515
);
1616
}
1717
}

examples/todo/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import Header from './Header';
33
import Body from './Body';
4-
import { root } from 'redux';
4+
import { dispatch } from 'redux';
55
import * as stores from './stores/index';
66

7-
@root(stores)
7+
@dispatch(stores)
88
export default class TodoApp {
99
render() {
1010
return (

examples/todo/Body.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PropTypes } from 'react';
2-
import { container } from 'redux';
2+
import { inject } from 'redux';
33
import { todoStore } from './stores/index';
44

5-
@container({
5+
@inject({
66
stores: { todos: todoStore }
77
})
88
export default class Body {

examples/todo/Header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PropTypes } from 'react';
2-
import { container } from 'redux';
2+
import { inject } from 'redux';
33
import { addTodo } from './actions/index';
44

5-
@container({
5+
@inject({
66
actions: { addTodo }
77
})
88
export default class Header {

src/Root.js renamed to src/Dispatcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PropTypes } from 'react';
22
import createDispatcher from './createDispatcher';
33

4-
export default class ReduxRoot {
4+
export default class ReduxDispatcher {
55
static propTypes = {
66
stores: PropTypes.object.isRequired,
77
children: PropTypes.func.isRequired

src/Container.js renamed to src/Injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import invariant from 'invariant';
55
import isPlainObject from 'lodash/lang/isPlainObject';
66
import isFunction from 'lodash/lang/isFunction';
77

8-
export default class ReduxContainer extends Component {
8+
export default class ReduxInjector extends Component {
99
static contextTypes = {
1010
redux: PropTypes.object.isRequired
1111
};

src/addons/dispatch.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import Dispatcher from '../Dispatcher';
3+
import getDisplayName from './getDisplayName';
4+
5+
export default function dispatch(stores) {
6+
return DecoratedComponent => class ReduxDispatcherDecorator {
7+
static displayName = `ReduxDispatcher(${getDisplayName(DecoratedComponent)})`;
8+
9+
render() {
10+
return (
11+
<Dispatcher stores={stores}>
12+
{props => <DecoratedComponent {...this.props} {...props} />}
13+
</Dispatcher>
14+
);
15+
}
16+
};
17+
}

src/addons/container.js renamed to src/addons/inject.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import React from 'react';
2-
import Container from '../Container';
2+
import Injector from '../Injector';
33
import getDisplayName from './getDisplayName';
44

55
function mergePropsStateAndActions({ props, state, actions }) {
66
return { ...props, ...state, ...actions };
77
}
88

9-
export default function container(
9+
export default function inject(
1010
{ actions: actionsToInject, stores: storesToConnect },
1111
getChildProps = mergePropsStateAndActions
1212
) {
13-
return DecoratedComponent => class ReduxContainerDecorator {
14-
static displayName = `ReduxContainer(${getDisplayName(DecoratedComponent)})`;
13+
return DecoratedComponent => class ReduxInjectorDecorator {
14+
static displayName = `ReduxInjector(${getDisplayName(DecoratedComponent)})`;
1515

1616
constructor() {
1717
this.renderChild = this.renderChild.bind(this);
1818
}
1919

2020
render() {
2121
return (
22-
<Container actions={actionsToInject}
23-
stores={storesToConnect}>
22+
<Injector actions={actionsToInject}
23+
stores={storesToConnect}>
2424
{this.renderChild}
25-
</Container>
25+
</Injector>
2626
);
2727
}
2828

src/addons/root.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Container components
2-
export Root from './Root';
3-
export Container from './Container';
1+
// Wrapper components
2+
export Dispatcher from './Dispatcher';
3+
export Injector from './Injector';
44

55
// Higher-order components (decorators)
6-
export root from './addons/root';
7-
export container from './addons/container';
6+
export dispatch from './addons/dispatch';
7+
export inject from './addons/inject';

0 commit comments

Comments
 (0)