Skip to content

Commit 8fc963e

Browse files
committed
fix(view): correctly proxy react specific getter only static props
1 parent 7b09387 commit 8fc963e

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

__tests__/staticProps.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ describe('static props', () => {
2424
expect(ViewFuncComp.propTypes).toBe(FuncComp.propTypes)
2525
expect(ViewFuncComp.defaultProps).toBe(FuncComp.defaultProps)
2626
})
27+
28+
test('view() should proxy react specific static getters', () => {
29+
class Comp extends Component {
30+
static get defaultProps () {
31+
return { key: 'value' }
32+
}
33+
}
34+
35+
const ViewComp = view(Comp)
36+
expect(ViewComp.defaultProps).toEqual(Comp.defaultProps)
37+
})
2738
})

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@
9191
"moment": "2.20.1",
9292
"pre-push": "0.1.1",
9393
"prettier": "^1.6.1",
94-
"react": "^16.3.0-alpha.1",
95-
"react-dom": "^16.3.0-alpha.1",
96-
"react-test-renderer": "^16.3.0-alpha.1",
94+
"react": "^16.3.0",
95+
"react-dom": "^16.3.0",
96+
"react-test-renderer": "^16.3.0",
9797
"rollup": "^0.56.0",
9898
"rollup-plugin-auto-external": "^1.0.0",
9999
"rollup-plugin-babel": "^3.0.2",
100100
"rollup-plugin-node-resolve": "^3.0.0",
101101
"sinon": "^4.3.0",
102-
"standard": "10.0.3"
102+
"standard": "^10.0.3"
103103
},
104104
"engines": {
105105
"node": ">=6.0.0"

src/view.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ export default function view (Comp, { devtool: rawDevtool } = {}) {
1111

1212
// return a HOC which overwrites render, shouldComponentUpdate and componentWillUnmount
1313
// it decides when to run the new reactive methods and when to proxy to the original methods
14-
return class ReactiveHOC extends BaseComp {
15-
static displayName = Comp.displayName || Comp.name;
16-
static contextTypes = Comp.contextTypes;
17-
static childContextTypes = Comp.childContextTypes;
18-
static propTypes = Comp.propTypes;
19-
static defaultProps = Comp.defaultProps;
20-
14+
class ReactiveHOC extends BaseComp {
2115
constructor (props, context) {
2216
super(props, context)
2317

@@ -81,4 +75,16 @@ export default function view (Comp, { devtool: rawDevtool } = {}) {
8175
unobserve(this.render)
8276
}
8377
}
78+
79+
ReactiveHOC.displayName = Comp.displayName || Comp.name;
80+
// these are inherited by class components,
81+
// but have to be copied for function components
82+
if (isStatelessComp) {
83+
ReactiveHOC.contextTypes = Comp.contextTypes;
84+
ReactiveHOC.childContextTypes = Comp.childContextTypes;
85+
ReactiveHOC.propTypes = Comp.propTypes;
86+
ReactiveHOC.defaultProps = Comp.defaultProps;
87+
}
88+
89+
return ReactiveHOC
8490
}

0 commit comments

Comments
 (0)