File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { Component , PropTypes , Children } from 'react'
2
+ import Subscription from '../utils/Subscription'
2
3
import storeShape from '../utils/storeShape'
3
4
import warning from '../utils/warning'
4
5
@@ -20,7 +21,7 @@ function warnAboutReceivingStore() {
20
21
21
22
export default class Provider extends Component {
22
23
getChildContext ( ) {
23
- return { store : this . store }
24
+ return { store : this . store , storeSubscription : null }
24
25
}
25
26
26
27
constructor ( props , context ) {
@@ -49,6 +50,7 @@ Provider.propTypes = {
49
50
children : PropTypes . element . isRequired
50
51
}
51
52
Provider . childContextTypes = {
52
- store : storeShape . isRequired
53
+ store : storeShape . isRequired ,
54
+ storeSubscription : PropTypes . instanceOf ( Subscription )
53
55
}
54
56
Provider . displayName = 'Provider'
Original file line number Diff line number Diff line change @@ -109,6 +109,29 @@ describe('React', () => {
109
109
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
110
110
expect ( spy . calls . length ) . toBe ( 0 )
111
111
} )
112
+
113
+ it ( 'should handle subscriptions correctly when there is nested Providers' , ( ) => {
114
+ const reducer = ( state = 0 , action ) => ( action . type === 'INC' ? state + 1 : state )
115
+
116
+ const innerStore = createStore ( reducer )
117
+ const innerMapStateToProps = expect . createSpy ( ) . andCall ( state => ( { count : state } ) )
118
+ @connect ( innerMapStateToProps )
119
+ class Inner extends Component {
120
+ render ( ) { return < div > { this . props . count } </ div > }
121
+ }
122
+
123
+ const outerStore = createStore ( reducer )
124
+ @connect ( state => ( { count : state } ) )
125
+ class Outer extends Component {
126
+ render ( ) { return < Provider store = { innerStore } > < Inner /> </ Provider > }
127
+ }
128
+
129
+ TestUtils . renderIntoDocument ( < Provider store = { outerStore } > < Outer /> </ Provider > )
130
+ expect ( innerMapStateToProps . calls . length ) . toBe ( 1 )
131
+
132
+ innerStore . dispatch ( { type : 'INC' } )
133
+ expect ( innerMapStateToProps . calls . length ) . toBe ( 2 )
134
+ } )
112
135
} )
113
136
114
137
it ( 'should pass state consistently to mapState' , ( ) => {
You can’t perform that action at this time.
0 commit comments