@@ -34,8 +34,8 @@ export default function createConnect(React) {
34
34
// Helps track hot reloading.
35
35
const version = nextVersion ++ ;
36
36
37
- function computeStateProps ( context ) {
38
- const state = context . store . getState ( ) ;
37
+ function computeStateProps ( store ) {
38
+ const state = store . getState ( ) ;
39
39
const stateProps = finalMapStateToProps ( state ) ;
40
40
invariant (
41
41
isPlainObject ( stateProps ) ,
@@ -45,8 +45,8 @@ export default function createConnect(React) {
45
45
return stateProps ;
46
46
}
47
47
48
- function computeDispatchProps ( context ) {
49
- const { dispatch } = context . store ;
48
+ function computeDispatchProps ( store ) {
49
+ const { dispatch } = store ;
50
50
const dispatchProps = finalMapDispatchToProps ( dispatch ) ;
51
51
invariant (
52
52
isPlainObject ( dispatchProps ) ,
@@ -72,7 +72,7 @@ export default function createConnect(React) {
72
72
static WrappedComponent = WrappedComponent ;
73
73
74
74
static contextTypes = {
75
- store : storeShape . isRequired
75
+ store : storeShape
76
76
} ;
77
77
78
78
shouldComponentUpdate ( nextProps , nextState ) {
@@ -82,13 +82,17 @@ export default function createConnect(React) {
82
82
constructor ( props , context ) {
83
83
super ( props , context ) ;
84
84
this . version = version ;
85
- this . stateProps = computeStateProps ( context ) ;
86
- this . dispatchProps = computeDispatchProps ( context ) ;
85
+ this . store = props . store || context . store ;
86
+
87
+ invariant ( this . store , '`store` must be passed in via the context or props' ) ;
88
+
89
+ this . stateProps = computeStateProps ( this . store ) ;
90
+ this . dispatchProps = computeDispatchProps ( this . store ) ;
87
91
this . state = this . computeNextState ( ) ;
88
92
}
89
93
90
94
recomputeStateProps ( ) {
91
- const nextStateProps = computeStateProps ( this . context ) ;
95
+ const nextStateProps = computeStateProps ( this . store ) ;
92
96
if ( shallowEqual ( nextStateProps , this . stateProps ) ) {
93
97
return false ;
94
98
}
@@ -98,7 +102,7 @@ export default function createConnect(React) {
98
102
}
99
103
100
104
recomputeDispatchProps ( ) {
101
- const nextDispatchProps = computeDispatchProps ( this . context ) ;
105
+ const nextDispatchProps = computeDispatchProps ( this . store ) ;
102
106
if ( shallowEqual ( nextDispatchProps , this . dispatchProps ) ) {
103
107
return false ;
104
108
}
@@ -128,7 +132,7 @@ export default function createConnect(React) {
128
132
129
133
trySubscribe ( ) {
130
134
if ( shouldSubscribe && ! this . unsubscribe ) {
131
- this . unsubscribe = this . context . store . subscribe ( ::this . handleChange ) ;
135
+ this . unsubscribe = this . store . subscribe ( ::this . handleChange ) ;
132
136
this . handleChange ( ) ;
133
137
}
134
138
}
0 commit comments