Skip to content

Commit 3d2df4f

Browse files
committed
withAltContext as decorator
1 parent caa89f5 commit 3d2df4f

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/utils/withAltContext.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import React from 'react'
22

3-
export default function withAltContext(flux, Component) {
4-
return React.createClass({
5-
childContextTypes: {
6-
flux: React.PropTypes.object
7-
},
3+
export default function withAltContext(flux) {
4+
return function (Component) {
5+
return React.createClass({
6+
childContextTypes: {
7+
flux: React.PropTypes.object
8+
},
89

9-
getChildContext() {
10-
return { flux }
11-
},
10+
getChildContext() {
11+
return { flux }
12+
},
1213

13-
render() {
14-
return React.createElement(Component, this.props)
15-
}
16-
})
14+
render() {
15+
return React.createElement(Component, this.props)
16+
}
17+
})
18+
}
1719
}

test/store-listener-component-test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ export default {
119119
'works with context'() {
120120
const flux = new Flux()
121121

122-
const ContextComponent = withAltContext(flux, AltContainer)
122+
@withAltContext(flux)
123+
class ContextComponent extends React.Component {
124+
render() {
125+
return <AltContainer />
126+
}
127+
}
128+
123129
const tree = TestUtils.renderIntoDocument(<ContextComponent />)
124130

125131
const contextComponent = TestUtils.findRenderedComponentWithType(
@@ -149,7 +155,7 @@ export default {
149155
}
150156
})
151157

152-
const WrappedComponent = withAltContext(flux, TestComponent)
158+
const WrappedComponent = withAltContext(flux)(TestComponent)
153159

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

0 commit comments

Comments
 (0)