Skip to content

Commit

Permalink
Fixes passing in context to nested components
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Apr 19, 2015
1 parent 8f41626 commit 21d4d6d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/mixinContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ function mixinContainer(React) {
flux: React.PropTypes.object
},

childContextTypes: {
flux: React.PropTypes.object
},

getChildContext: function () {
var flux = this.props.flux || this.context.flux
return flux ? { flux: flux } : {}
},

getInitialState: function () {
if (this.props.stores && this.props.store) {
throw new ReferenceError('Cannot define both store and stores')
Expand Down
40 changes: 40 additions & 0 deletions test/store-listener-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,45 @@ export default {
assert.isDefined(strong, 'component exists')
assert(strong.props.x === 1337, 'and we have props from TestStore')
},

'nested components and context'() {
const flux = new Flux()

const View = React.createClass({
render() {
return <SubView />
}
})

const SubView = React.createClass({ render() {
return (
<AltContainer>
<InsideComponent />
</AltContainer>
)
} })

const InsideComponent = React.createClass({
render() {
return <span flux={this.props.flux} />
}
})


const App = React.createClass({
render() {
return (
<AltContainer flux={flux}>
<View />
</AltContainer>
)
}
})

const node = TestUtils.renderIntoDocument(<App />)
const span = TestUtils.findRenderedDOMComponentWithTag(node, 'span')

assert.instanceOf(span.props.flux, Flux)
},
}
}

0 comments on commit 21d4d6d

Please sign in to comment.