Sha256: 2d9b794462ed6512a6c673c4bda133d640de25fc141649c244b2d66bb2e9ba0a

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

module React
  module Component
    module DslInstanceMethods
      def children
        if `#{@native}.props.children==undefined`
          nodes = []
        else
          nodes = [`#{@native}.props.children`].flatten
        end
        class << nodes
          include Enumerable

          def to_n
            self
          end

          def each(&block)
            if block_given?
              %x{
                    React.Children.forEach(#{self.to_n}, function(context){
              #{yield React::Element.new(`context`)}
                    })
              }
              nil
            else
              Enumerator.new(`React.Children.count(#{self.to_n})`) do |y|
                %x{
                      React.Children.forEach(#{self.to_n}, function(context){
                #{y << Element.new(`context`)}
                      })
                }
              end
            end
          end
        end

        nodes
      end

      def params
        @props_wrapper
      end

      def props
        Hash.new(`#{@native}.props`)
      end

      def refs
        Hash.new(`#{@native}.refs`)
      end

      def state
        @state_wrapper ||= StateWrapper.new(@native, self)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reactrb-0.8.8 lib/react/component/dsl_instance_methods.rb
reactrb-0.8.7 lib/react/component/dsl_instance_methods.rb
reactrb-0.8.6 lib/react/component/dsl_instance_methods.rb
reactrb-0.8.5 lib/react/component/dsl_instance_methods.rb
reactrb-0.8.4 lib/react/component/dsl_instance_methods.rb