Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit b9cd364

Browse files
committed
createClass -> class extends
disable propTypes
1 parent b9d104c commit b9cd364

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

lib/react/api.rb

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,56 +46,61 @@ def self.create_native_react_class(type)
4646
render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
4747
# this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
4848
@@component_classes[type] ||= %x{
49-
React.createClass({
50-
displayName: #{type.name},
51-
propTypes: #{type.respond_to?(:prop_types) ? type.prop_types.to_n : `{}`},
52-
getDefaultProps: function(){
49+
class extends React.Component {
50+
constructor(props) {
51+
super(props);
52+
this.displayName = #{type.name};
53+
this.mixins = #{type.respond_to?(:native_mixins) ? type.native_mixins : `[]`};
54+
this.statics = #{type.respond_to?(:static_call_backs) ? type.static_call_backs.to_n : `{}`};
55+
}
56+
static get defaultProps() {
5357
return #{type.respond_to?(:default_props) ? type.default_props.to_n : `{}`};
54-
},
55-
mixins: #{type.respond_to?(:native_mixins) ? type.native_mixins : `[]`},
56-
statics: #{type.respond_to?(:static_call_backs) ? type.static_call_backs.to_n : `{}`},
57-
componentWillMount: function() {
58+
}
59+
/* static get propTypes() {
60+
return #{type.respond_to?(:prop_types) ? type.prop_types.to_n : `{}`};
61+
} */
62+
componentWillMount() {
5863
var instance = this._getOpalInstance.apply(this);
5964
return #{`instance`.component_will_mount if type.method_defined? :component_will_mount};
60-
},
61-
componentDidMount: function() {
65+
}
66+
componentDidMount() {
6267
var instance = this._getOpalInstance.apply(this);
6368
return #{`instance`.component_did_mount if type.method_defined? :component_did_mount};
64-
},
65-
componentWillReceiveProps: function(next_props) {
69+
}
70+
componentWillReceiveProps(next_props) {
6671
var instance = this._getOpalInstance.apply(this);
6772
return #{`instance`.component_will_receive_props(Hash.new(`next_props`)) if type.method_defined? :component_will_receive_props};
68-
},
69-
shouldComponentUpdate: function(next_props, next_state) {
73+
}
74+
shouldComponentUpdate(next_props, next_state) {
7075
var instance = this._getOpalInstance.apply(this);
7176
return #{`instance`.should_component_update?(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :should_component_update?};
72-
},
73-
componentWillUpdate: function(next_props, next_state) {
77+
}
78+
componentWillUpdate(next_props, next_state) {
7479
var instance = this._getOpalInstance.apply(this);
7580
return #{`instance`.component_will_update(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :component_will_update};
76-
},
77-
componentDidUpdate: function(prev_props, prev_state) {
81+
}
82+
componentDidUpdate(prev_props, prev_state) {
7883
var instance = this._getOpalInstance.apply(this);
7984
return #{`instance`.component_did_update(Hash.new(`prev_props`), Hash.new(`prev_state`)) if type.method_defined? :component_did_update};
80-
},
81-
componentWillUnmount: function() {
85+
}
86+
componentWillUnmount() {
8287
var instance = this._getOpalInstance.apply(this);
8388
return #{`instance`.component_will_unmount if type.method_defined? :component_will_unmount};
84-
},
85-
_getOpalInstance: function() {
89+
}
90+
_getOpalInstance() {
8691
if (this.__opalInstance == undefined) {
8792
var instance = #{type.new(`this`)};
8893
} else {
8994
var instance = this.__opalInstance;
9095
}
9196
this.__opalInstance = instance;
9297
return instance;
93-
},
94-
render: function() {
98+
}
99+
render() {
95100
var instance = this._getOpalInstance.apply(this);
96101
return #{`instance`.send(render_fn).to_n};
97102
}
98-
})
103+
}
99104
}
100105
end
101106

0 commit comments

Comments
 (0)