Skip to content

Commit f6649b9

Browse files
committed
closes #64
1 parent 96b01e9 commit f6649b9

File tree

3 files changed

+21
-54
lines changed

3 files changed

+21
-54
lines changed

ruby/hyper-router/lib/hyperstack/internal/router/class_methods.rb

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,6 @@ def location
1414
Hyperstack::Router::Location.new(`#{history.to_n}.location`)
1515
end
1616

17-
# def xrender(container = nil, params = {}, &block)
18-
# if container
19-
# container = container.type if container.is_a? Hyperstack::Component::Element
20-
# select_router do
21-
# __hyperstack_component_run_post_render_hooks(
22-
# Hyperstack::Internal::Component::RenderingContext.render(container, params) do
23-
# instance_eval(&block) if block
24-
# end
25-
# )
26-
# end
27-
# else
28-
# select_router { __hyperstack_component_run_post_render_hooks(instance_eval(&block)) }
29-
# end
30-
# end
31-
#
32-
# def select_router(&block)
33-
# if Hyperstack::Component::IsomorphicHelpers.on_opal_server?
34-
# prerender_router(&block)
35-
# else
36-
# render_router(&block)
37-
# end
38-
# end
39-
40-
#alias route render
41-
4217
private
4318

4419
def browser_history
@@ -52,30 +27,6 @@ def hash_history(*args)
5227
def memory_history(*args)
5328
@__memory_history ||= React::Router::History.current.create_memory_history(*args)
5429
end
55-
56-
# def render_router(&block)
57-
# define_method(:__hyperstack_component_render) do
58-
# self.class.history :browser unless history
59-
#
60-
# React::Router::Router(history: history.to_n) do
61-
# instance_eval(&block)
62-
# end
63-
# end
64-
# end
65-
#
66-
# def prerender_router(&block)
67-
# define_method(:__hyperstack_component_render) do
68-
# location = {}.tap do |hash|
69-
# pathname, search = IsomorphicMethods.request_fullpath.split('?', 2)
70-
# hash[:pathname] = pathname
71-
# hash[:search] = search ? "?#{search}" : ''
72-
# end
73-
#
74-
# React::Router::StaticRouter(location: location.to_n, context: IsomorphicMethods.ctx) do
75-
# instance_eval(&block)
76-
# end
77-
# end
78-
# end
7930
end
8031
end
8132
end

ruby/hyper-router/lib/hyperstack/router.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ def __hyperstack_router_wrapper(&block)
1010
end
1111
end
1212

13+
def __eval_block(block)
14+
result = instance_eval(&block)
15+
if result.is_a?(String) ||
16+
(result.respond_to?(:acts_as_string?) && result.acts_as_string?)
17+
# hyper-mesh DummyValues respond to acts_as_string, and must
18+
# be converted to spans INSIDE the parent, otherwise the waiting_on_resources
19+
# flag will get set in the wrong context
20+
result = Hyperstack::Internal::Component::RenderingContext
21+
.render(:span) { result.to_s }
22+
end
23+
result
24+
end
25+
1326
def __hyperstack_render_router(&block)
1427
instance_eval do
1528
self.class.history :browser unless history
1629
React::Router::Router(history: history.to_n) do
17-
instance_eval(&block)
30+
__eval_block(block)
1831
end
1932
end
2033
end
@@ -27,7 +40,7 @@ def __hyperstack_prerender_router(&block)
2740
location: location,
2841
context: Hyperstack::Internal::Router::IsomorphicMethods.ctx
2942
) do
30-
instance_eval(&block)
43+
__eval_block(block)
3144
end
3245
end
3346
end

ruby/hyper-router/spec/hyper-router/basic_dsl_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
expect(page.current_path).to eq('/topics/components')
2020
end
2121

22-
it 'a routers render method can return a string', skip: 'breaking - see issue #64' do
23-
mount 'SimpleStringRouter'
24-
expect(page).to have_content('a simple string')
22+
[:server_only, :client_only].each do |render_on|
23+
it "a routers render method can return a string (#{render_on})" do
24+
client_option render_on: render_on
25+
mount 'SimpleStringRouter'
26+
expect(page).to have_content('a simple string')
27+
end
2528
end
2629
end

0 commit comments

Comments
 (0)