Sha256: 5ad9e540ad7e6ce911358fff128b19697a7f1e22a5ac1342fe2b3b8791bd199d

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

module React
  module Component
    class Styles
      def initialize(native, props_prop = false)
        @native = native
        @props_prop = props_prop
      end

      def method_missing(prop, *args, &block)
        %x{
          let value;
          if (#@props_prop) {
            if (!#@native.props[#@props_prop] || typeof #@native.props[#@props_prop][prop] === 'undefined') { return #{nil}; }
            value = #@native.props[#@props_prop][prop];
          } else {
            if (!#@native || typeof #@native[prop] === 'undefined') { return #{nil}; }
            value = #@native[prop];
          }
          if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) { return value; }
          if (typeof value === 'function') { return #{Proc.new { `value()` }} }
          return Opal.React.Component.Styles.$new(value);
        }
      end

      def to_h
        %x{
          if (#@props_prop) { return Opal.Hash.$new(#@native.props[#@props_prop]); }
          else { return Opal.Hash.$new(#@native); }
        }
      end

      def to_n
        %x{
          if (#@props_prop) { return #@native.props[#@props_prop]; }
          else { return #@native; }
        }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
isomorfeus-react-16.11.1 lib/react/component/styles.rb
isomorfeus-react-16.11.0 lib/react/component/styles.rb
isomorfeus-react-16.10.17 lib/react/component/styles.rb
isomorfeus-react-16.10.16 lib/react/component/styles.rb
isomorfeus-react-16.10.14 lib/react/component/styles.rb
isomorfeus-react-16.10.13 lib/react/component/styles.rb
isomorfeus-react-16.10.12 lib/react/component/styles.rb