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 11import { Component , PropTypes , Children } from 'react'
2+ import Subscription from '../utils/Subscription'
23import storeShape from '../utils/storeShape'
34import warning from '../utils/warning'
45
@@ -20,7 +21,7 @@ function warnAboutReceivingStore() {
2021
2122export default class Provider extends Component {
2223 getChildContext ( ) {
23- return { store : this . store }
24+ return { store : this . store , storeSubscription : null }
2425 }
2526
2627 constructor ( props , context ) {
@@ -49,6 +50,7 @@ Provider.propTypes = {
4950 children : PropTypes . element . isRequired
5051}
5152Provider . childContextTypes = {
52- store : storeShape . isRequired
53+ store : storeShape . isRequired ,
54+ storeSubscription : PropTypes . instanceOf ( Subscription )
5355}
5456Provider . displayName = 'Provider'
Original file line number Diff line number Diff line change @@ -109,6 +109,29 @@ describe('React', () => {
109109 expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
110110 expect ( spy . calls . length ) . toBe ( 0 )
111111 } )
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+ } )
112135 } )
113136
114137 it ( 'should pass state consistently to mapState' , ( ) => {
You can’t perform that action at this time.
0 commit comments