Skip to content

Commit c4c3c1a

Browse files
author
Keyan Zhang
committed
dont bind getChildContext
1 parent 011371d commit c4c3c1a

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

transforms/__testfixtures__/class-test2.input.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,34 @@ var ComponentWithInconvertibleMixins = React.createClass({
8383
);
8484
},
8585
});
86+
87+
// taken from https://facebook.github.io/react/docs/context.html#updating-context
88+
var MediaQuery = React.createClass({
89+
childContextTypes: {
90+
type: React.PropTypes.string,
91+
},
92+
93+
getInitialState: function() {
94+
return {type:'desktop'};
95+
},
96+
97+
getChildContext: function() {
98+
return {type: this.state.type};
99+
},
100+
101+
componentDidMount: function() {
102+
const checkMediaQuery = () => {
103+
const type = window.matchMedia('(min-width: 1025px)').matches ? 'desktop' : 'mobile';
104+
if (type !== this.state.type) {
105+
this.setState({type});
106+
}
107+
};
108+
109+
window.addEventListener('resize', checkMediaQuery);
110+
checkMediaQuery();
111+
},
112+
113+
render: function() {
114+
return this.props.children;
115+
},
116+
});

transforms/__testfixtures__/class-test2.output.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,32 @@ var ComponentWithInconvertibleMixins = React.createClass({
8787
);
8888
},
8989
});
90+
91+
// taken from https://facebook.github.io/react/docs/context.html#updating-context
92+
class MediaQuery extends React.Component {
93+
static childContextTypes = {
94+
type: React.PropTypes.string,
95+
};
96+
97+
state = {type:'desktop'};
98+
99+
getChildContext() {
100+
return {type: this.state.type};
101+
}
102+
103+
componentDidMount() {
104+
const checkMediaQuery = () => {
105+
const type = window.matchMedia('(min-width: 1025px)').matches ? 'desktop' : 'mobile';
106+
if (type !== this.state.type) {
107+
this.setState({type});
108+
}
109+
};
110+
111+
window.addEventListener('resize', checkMediaQuery);
112+
checkMediaQuery();
113+
}
114+
115+
render() {
116+
return this.props.children;
117+
}
118+
}

transforms/class.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = (file, api, options) => {
2727
componentWillMount: true,
2828
componentWillUpdate: true,
2929
componentWillUnmount: true,
30+
getChildContext: true,
3031
getDefaultProps: true,
3132
getInitialState: true,
3233
render: true,

0 commit comments

Comments
 (0)