Sha256: 68a3146b0b69035ccb8635b37f01ab584043a8eee6d274e4853141df61747cdf

Contents?: true

Size: 1.57 KB

Versions: 29

Compression:

Stored size: 1.57 KB

Contents

module React
  module Component
    module NativeComponentValidateProp
      # 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
      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
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
isomorfeus-react-16.9.9 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.8 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.7 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.6 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.5 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.4 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.3 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.2 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.1 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.9.0 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.9 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.8 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.7 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.6 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.5 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.4 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.3 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.2 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.1 lib/react/component/native_component_validate_prop.rb
isomorfeus-react-16.8.0 lib/react/component/native_component_validate_prop.rb