lib/react/component/api.rb in isomorfeus-react-16.8.0 vs lib/react/component/api.rb in isomorfeus-react-16.8.1
- old
+ new
@@ -55,57 +55,33 @@
self.react_component.defaultProps[name] = options.$fetch("default");
}
end
if options.has_key?(:class)
%x{
- if (typeof self.react_component.propTypes == "undefined") {
- self.react_component.propTypes = {};
- self.react_component.propValidations = {};
- self.react_component.propValidations[name] = {};
- }
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
+ Opal.React.set_validate_prop(self, name);
self.react_component.propValidations[name].ruby_class = options.$fetch("class");
}
elsif options.has_key?(:is_a)
%x{
- if (typeof self.react_component.propTypes == "undefined") {
- self.react_component.propTypes = {};
- self.react_component.propValidations = {};
- self.react_component.propValidations[name] = {};
- }
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
+ Opal.React.set_validate_prop(self, name);
self.react_component.propValidations[name].is_a = options.$fetch("is_a");
}
end
if options.has_key?(:required)
%x{
- if (typeof self.react_component.propTypes == "undefined") {
- self.react_component.propTypes = {};
- self.react_component.propValidations = {};
- self.react_component.propValidations[name] = {};
- }
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
+ Opal.React.set_validate_prop(self, name);
self.react_component.propValidations[name].required = options.$fetch("required");
}
elsif !options.has_key?(:default)
%x{
- if (typeof self.react_component.propTypes == "undefined") {
- self.react_component.propTypes = {};
- self.react_component.propValidations = {};
- }
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
+ Opal.React.set_validate_prop(self, name);
self.react_component.propValidations[name].required = true;
}
end
else
%x{
- if (typeof self.react_component.propTypes == "undefined") {
- self.react_component.propTypes = {};
- self.react_component.propValidations = {};
- self.react_component.propValidations[name] = {};
- }
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
+ Opal.React.set_validate_prop(self, name);
self.react_component.propValidations[name].required = options.$fetch("required");
}
end
end
@@ -130,9 +106,18 @@
# this maybe needs instance_exec too
@native.JS.forceUpdate(`function() { block.$call(); }`)
else
@native.JS.forceUpdate
end
+ end
+
+ def ref(name)
+ `#@native[name]`
+ end
+
+ def ruby_ref(name)
+ return `#@native[name]` if `(typeof #@native[name] === 'function')`
+ React::Ref::new(`#@native[name]`)
end
def set_state(updater, &callback)
@state.set_state(updater, &callback)
end
\ No newline at end of file