Class: React::Children
- Includes:
- Enumerable
- Defined in:
- lib/react/children.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(children) ⇒ Children
constructor
A new instance of Children.
- #length ⇒ Object (also: #size)
- #render ⇒ Object
- #to_proc ⇒ Object
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 |
#length ⇒ Object Also known as: size
33 34 35 |
# File 'lib/react/children.rb', line 33 def length @length ||= `React.Children.count(#{@children})` end |
#render ⇒ Object
9 10 11 |
# File 'lib/react/children.rb', line 9 def render each(&:render) end |
#to_proc ⇒ Object
13 14 15 |
# File 'lib/react/children.rb', line 13 def to_proc -> () { render } end |