Skip to content

Commit 00790d4

Browse files
author
Keyan Zhang
committed
added support for mixins
1 parent 6d9e3cb commit 00790d4

File tree

5 files changed

+173
-69
lines changed

5 files changed

+173
-69
lines changed

transforms/__testfixtures__/property-initializer-2.input.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
var React = require('React');
4+
var ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin');
5+
var FooBarMixin = require('FooBarMixin');
46

57
var ComponentWithNonSimpleInitialState = React.createClass({
68
statics: {
@@ -44,3 +46,35 @@ module.exports = React.createClass({
4446
return <div />;
4547
},
4648
});
49+
50+
var ComponentWithOnlyPureRenderMixin = React.createClass({
51+
mixins: [ReactComponentWithPureRenderMixin],
52+
53+
getInitialState: function() {
54+
return {
55+
counter: this.props.initialNumber + 1,
56+
};
57+
},
58+
59+
render: function() {
60+
return (
61+
<div>{this.state.counter}</div>
62+
);
63+
},
64+
});
65+
66+
var ComponentWithInconvertibleMixins = React.createClass({
67+
mixins: [ReactComponentWithPureRenderMixin, FooBarMixin],
68+
69+
getInitialState: function() {
70+
return {
71+
counter: this.props.initialNumber + 1,
72+
};
73+
},
74+
75+
render: function() {
76+
return (
77+
<div>{this.state.counter}</div>
78+
);
79+
},
80+
});

transforms/__testfixtures__/property-initializer-2.output.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22

33
var React = require('React');
4+
var ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin');
5+
var FooBarMixin = require('FooBarMixin');
46

57
class ComponentWithNonSimpleInitialState extends React.Component {
6-
static foo = 'bar';
78
static iDontKnowWhyYouNeedThis = true; // but comment it
9+
static foo = 'bar';
810

911
constructor(props, context) {
1012
super(props, context);
@@ -23,14 +25,14 @@ class ComponentWithNonSimpleInitialState extends React.Component {
2325

2426
// Comment
2527
module.exports = class extends React.Component {
26-
static defaultProps = {
27-
foo: 12,
28-
};
29-
3028
static propTypes = {
3129
foo: React.PropTypes.bool,
3230
};
3331

32+
static defaultProps = {
33+
foo: 12,
34+
};
35+
3436
state = function() { // non-simple
3537
var data = 'bar';
3638
return {
@@ -42,3 +44,35 @@ module.exports = class extends React.Component {
4244
return <div />;
4345
}
4446
};
47+
48+
class ComponentWithOnlyPureRenderMixin extends React.PureComponent {
49+
constructor(props, context) {
50+
super(props, context);
51+
52+
this.state = {
53+
counter: props.initialNumber + 1,
54+
};
55+
}
56+
57+
render() {
58+
return (
59+
<div>{this.state.counter}</div>
60+
);
61+
}
62+
}
63+
64+
var ComponentWithInconvertibleMixins = React.createClass({
65+
mixins: [ReactComponentWithPureRenderMixin, FooBarMixin],
66+
67+
getInitialState: function() {
68+
return {
69+
counter: this.props.initialNumber + 1,
70+
};
71+
},
72+
73+
render: function() {
74+
return (
75+
<div>{this.state.counter}</div>
76+
);
77+
},
78+
});

transforms/__testfixtures__/property-initializer.output.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ class MyComponent2 extends React.Component {
3434
}
3535

3636
class MyComponent3 extends React.Component {
37-
static defaultProps = function() {
38-
unboundFunc();
39-
return {
40-
linkifyEntities: true,
41-
highlightEntities: false,
42-
};
43-
}();
44-
45-
static funcThatDoesNothing = function(): void {};
46-
4737
static propTypes = {
4838
highlightEntities: React.PropTypes.bool,
4939
linkifyEntities: React.PropTypes.bool,
@@ -53,7 +43,16 @@ class MyComponent3 extends React.Component {
5343
}).isRequired,
5444
};
5545

46+
static defaultProps = function() {
47+
unboundFunc();
48+
return {
49+
linkifyEntities: true,
50+
highlightEntities: false,
51+
};
52+
}();
53+
5654
static someThing = 10;
55+
static funcThatDoesNothing = function(): void {};
5756

5857
constructor(props, context) {
5958
super(props, context);
@@ -64,6 +63,12 @@ class MyComponent3 extends React.Component {
6463
};
6564
}
6665

66+
_renderText = (text: string) => { // TODO no return type yet
67+
return <Text text={text} />;
68+
};
69+
70+
autobindMe = () => {};
71+
6772
// Function comment
6873
_renderRange = (text: string, range, bla: Promise<string>) => {
6974
var self = this;
@@ -90,12 +95,6 @@ class MyComponent3 extends React.Component {
9095
return text;
9196
};
9297

93-
_renderText = (text: string) => { // TODO no return type yet
94-
return <Text text={text} />;
95-
};
96-
97-
autobindMe = () => {};
98-
9998
_renderImageRange(text: string, range) { // TODO no return type yet
10099
var image = range.image;
101100
if (image) {

0 commit comments

Comments
 (0)