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

Commit 780e61e

Browse files
catmandozetachang
authored andcommitted
cant find components in anonymous scopes fixed
1 parent 9fc7272 commit 780e61e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/react/component/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def find_name_and_parent(component)
9494
private
9595

9696
def find_component(name)
97-
scopes = self.class.name.split('::').inject([Module]) do |nesting, next_const|
97+
scopes = "#{self.class.name}".split('::').inject([Module]) do |nesting, next_const|
9898
nesting + [nesting.last.const_get(next_const)]
9999
end.reverse
100100
scope = scopes.detect { |s| s.const_defined?(name) } || return

spec/react/opal_jquery_extensions_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
React::API.clear_component_class_cache
77
end
88

9-
it 'renders a top level component using render' do
9+
it 'renders a top level component using render with a block' do
10+
stub_const 'Foo', Class.new(React::Component::Base)
11+
Foo.class_eval do
12+
param :name
13+
def render
14+
"hello #{params.name}"
15+
end
16+
end
17+
test_div = Element.new(:div)
18+
test_div.render { Foo(name: 'fred') }
19+
expect(Element[test_div].find('span').html).to eq('hello fred')
20+
end
21+
22+
it 'renders a top level component using render with a container and params ' do
1023
test_div = Element.new(:div)
1124
test_div.render(:span, id: :render_test_span) { 'hello' }
1225
expect(Element[test_div].find('#render_test_span').html).to eq('hello')

0 commit comments

Comments
 (0)