Class: React::Children

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/react/children.rb

Instance Method Summary collapse

Constructor Details

#initialize(children) ⇒ Children

Returns a new instance of Children.



5
6
7
# File 'lib/react/children.rb', line 5

def initialize(children)
  @children = children
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/react/children.rb', line 17

def each(&block)
  return to_enum(__callee__) { length } unless block_given?
  return [] unless length > 0
  collection = []
  %x{
    React.Children.forEach(#{@children}, function(context){
      #{
        element = React::Element.new(`context`)
        block.call(element)
        collection << element
      }
    })
  }
  collection
end

#lengthObject Also known as: size



33
34
35
# File 'lib/react/children.rb', line 33

def length
  @length ||= `React.Children.count(#{@children})`
end

#renderObject



9
10
11
# File 'lib/react/children.rb', line 9

def render
  each(&:render)
end

#to_procObject



13
14
15
# File 'lib/react/children.rb', line 13

def to_proc
  -> () { render }
end