Skip to content

Commit bdaa2f5

Browse files
committed
Require "stores" to be an array, treat single value specially
1 parent 1028c8c commit bdaa2f5

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ import Counter from './Counter';
151151

152152
export default class CounterContainer {
153153
render() {
154-
// stores can be a single store or an array.
155-
// actions can only be a string -> function map.
154+
// stores must be an array.
155+
// actions must be a string -> function map.
156156
// props passed to children will combine these actions and state.
157157
return (
158-
<Container stores={counterStore}
158+
<Container stores={[counterStore]}
159159
actions={{ increment, decrement }}>
160160
{props => <Counter {...props} />}
161161
</Container>
@@ -177,7 +177,7 @@ import counterStore from './stores/counterStore';
177177

178178
@container({
179179
actions: { increment, decrement },
180-
stores: counterStore
180+
stores: [counterStore]
181181
})
182182
export default class Counter {
183183
static propTypes = {

examples/counter/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Counter from './Counter';
88
export default class CounterApp extends Component {
99
render() {
1010
return (
11-
<Container stores={counterStore} actions={{ increment, decrement }}>
11+
<Container stores={[counterStore]} actions={{ increment, decrement }}>
1212
{props => <Counter {...props} />}
1313
</Container>
1414
);

examples/todo/Body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { container } from 'redux';
33
import { todoStore } from './stores/index';
44

55
@container({
6-
stores: todoStore
6+
stores: [todoStore]
77
})
88
export default class Body {
99
static propTypes = {

src/Container.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export default class ReduxContainer extends Component {
1111
children: PropTypes.func.isRequired,
1212
actions: PropTypes.object.isRequired,
1313
stores: PropTypes.oneOfType([
14-
PropTypes.func.isRequired,
15-
PropTypes.arrayOf(PropTypes.func.isRequired).isRequired,
16-
PropTypes.object.isRequired
14+
PropTypes.arrayOf(PropTypes.func.isRequired).isRequired
1715
]).isRequired
1816
}
1917

@@ -43,13 +41,10 @@ export default class ReduxContainer extends Component {
4341
this.unsubscribe();
4442
}
4543

46-
let stores = props.stores;
47-
let mapState = identity;
48-
if (typeof props.stores === 'function') {
49-
const store = props.stores;
50-
stores = [store];
51-
mapState = state => state[store.name];
52-
}
44+
const { stores } = props;
45+
const mapState = (stores.length === 1) ?
46+
state => state[stores[0].name] :
47+
identity;
5348

5449
this.mapState = mapState;
5550
this.unsubscribe = observeStores(stores, this.handleChange);

0 commit comments

Comments
 (0)