Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 005cbfe

Browse files
committed
[opal-0.9] Fix React::Children
In Opal 0.9, attr_reader returns nil if the backing instance variable is “undefined” which makes `React.Children.count` return 1 and break all the Enumerable#each method.
1 parent 6686d0f commit 005cbfe

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/react/children.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module React
22
class Children
33
include Enumerable
4-
attr_reader :children
54

65
def initialize(children)
76
@children = children
@@ -12,7 +11,7 @@ def each(&block)
1211
return [] unless length > 0
1312
collection = []
1413
%x{
15-
React.Children.forEach(#{children}, function(context){
14+
React.Children.forEach(#{@children}, function(context){
1615
#{
1716
element = React::Element.new(`context`)
1817
block.call(element)
@@ -24,7 +23,7 @@ def each(&block)
2423
end
2524

2625
def length
27-
@length ||= `React.Children.count(#{children})`
26+
@length ||= `React.Children.count(#{@children})`
2827
end
2928
alias_method :size, :length
3029
end

0 commit comments

Comments
 (0)