Skip to content

Commit

Permalink
copy child context types in storeconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Lin committed Aug 21, 2015
1 parent 9f66b24 commit 74f033a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils/connectToStores.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function connectToStores(Spec, Component = Spec) {
)
}
})
if (Component.contextTypes) {
StoreConnection.contextTypes = Component.contextTypes
}

return StoreConnection
}
Expand Down
34 changes: 34 additions & 0 deletions test/connect-to-stores-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,40 @@ export default {
assert.include(output, 'Foo: Bar')
},

'component statics can see context properties'() {
const Child = connectToStores(React.createClass({
statics: {
getStores(props, context) {
return [context.store]
},
getPropsFromStores(props, context) {
return context.store.getState()
}
},
contextTypes: {
store: React.PropTypes.object
},
render() {
return <span>Foo: {this.props.foo}</span>
}
}))

const ContextComponent = React.createClass({
getChildContext() {
return { store: testStore }
},
childContextTypes: {
store: React.PropTypes.object
},
render() {
return <Child/>
}
})
const element = React.createElement(ContextComponent)
const output = React.renderToStaticMarkup(element)
assert.include(output, 'Foo: Bar')
},

'component can get use stores from props'() {
const LegacyComponent = React.createClass({
statics: {
Expand Down

0 comments on commit 74f033a

Please sign in to comment.