Module: React::Component::NativeComponentValidateProp
- Defined in:
- lib/react/component/native_component_validate_prop.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
for should_component_update we apply ruby semantics for comparing props to do so, we convert the props to ruby hashes and then compare this makes sure, that for example rubys Nil object gets handled properly.
Class Method Details
.extended(base) ⇒ Object
for should_component_update we apply ruby semantics for comparing props to do so, we convert the props to ruby hashes and then compare this makes sure, that for example rubys Nil object gets handled properly
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/react/component/native_component_validate_prop.rb', line 7 def self.extended(base) # language=JS %x{ base.react_component.prototype.validateProp = function(props, propName, componentName) { var prop_data = base.react_component.propValidations[propName]; if (!prop_data) { return true; }; var value = props[propName]; var result; if (typeof prop_data.ruby_class != "undefined") { result = (value.$class() == prop_data.ruby_class); if (!result) { return new Error('Invalid prop ' + propName + '! Expected ' + prop_data.ruby_class.$to_s() + ' but was ' + value.$class().$to_s() + '!'); } } else if (typeof prop_data.is_a != "undefined") { result = value["$is_a?"](prop_data.is_a); if (!result) { return new Error('Invalid prop ' + propName + '! Expected a child of ' + prop_data.is_a.$to_s() + '!'); } } if (typeof prop_data.required != "undefined") { if (prop_data.required && (typeof props[propName] == "undefined")) { return new Error('Prop ' + propName + ' is required but not given!'); } } return null; } } end |