Skip to content

Commit

Permalink
withAltContext as decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Apr 25, 2015
1 parent caa89f5 commit 3d2df4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/utils/withAltContext.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React from 'react'

export default function withAltContext(flux, Component) {
return React.createClass({
childContextTypes: {
flux: React.PropTypes.object
},
export default function withAltContext(flux) {
return function (Component) {
return React.createClass({
childContextTypes: {
flux: React.PropTypes.object
},

getChildContext() {
return { flux }
},
getChildContext() {
return { flux }
},

render() {
return React.createElement(Component, this.props)
}
})
render() {
return React.createElement(Component, this.props)
}
})
}
}
10 changes: 8 additions & 2 deletions test/store-listener-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ export default {
'works with context'() {
const flux = new Flux()

const ContextComponent = withAltContext(flux, AltContainer)
@withAltContext(flux)
class ContextComponent extends React.Component {
render() {
return <AltContainer />
}
}

const tree = TestUtils.renderIntoDocument(<ContextComponent />)

const contextComponent = TestUtils.findRenderedComponentWithType(
Expand Down Expand Up @@ -149,7 +155,7 @@ export default {
}
})

const WrappedComponent = withAltContext(flux, TestComponent)
const WrappedComponent = withAltContext(flux)(TestComponent)

const node = TestUtils.renderIntoDocument(<WrappedComponent />)
const span = TestUtils.findRenderedDOMComponentWithTag(node, 'span')
Expand Down

0 comments on commit 3d2df4f

Please sign in to comment.