Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, PropTypes, Children } from 'react'
import Subscription from '../utils/Subscription'
import storeShape from '../utils/storeShape'
import warning from '../utils/warning'

Expand All @@ -20,7 +21,7 @@ function warnAboutReceivingStore() {

export default class Provider extends Component {
getChildContext() {
return { store: this.store }
return { store: this.store, storeSubscription: null }
}

constructor(props, context) {
Expand Down Expand Up @@ -49,6 +50,7 @@ Provider.propTypes = {
children: PropTypes.element.isRequired
}
Provider.childContextTypes = {
store: storeShape.isRequired
store: storeShape.isRequired,
storeSubscription: PropTypes.instanceOf(Subscription)
}
Provider.displayName = 'Provider'
23 changes: 23 additions & 0 deletions test/components/Provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ describe('React', () => {
expect(child.context.store.getState()).toEqual(11)
expect(spy.calls.length).toBe(0)
})

it('should handle subscriptions correctly when there is nested Providers', () => {
const reducer = (state = 0, action) => (action.type === 'INC' ? state + 1 : state)

const innerStore = createStore(reducer)
const innerMapStateToProps = expect.createSpy().andCall(state => ({ count: state }))
@connect(innerMapStateToProps)
class Inner extends Component {
render() { return <div>{this.props.count}</div> }
}

const outerStore = createStore(reducer)
@connect(state => ({ count: state }))
class Outer extends Component {
render() { return <Provider store={innerStore}><Inner /></Provider> }
}

TestUtils.renderIntoDocument(<Provider store={outerStore}><Outer /></Provider>)
expect(innerMapStateToProps.calls.length).toBe(1)

innerStore.dispatch({ type: 'INC'})
expect(innerMapStateToProps.calls.length).toBe(2)
})
})

it('should pass state consistently to mapState', () => {
Expand Down