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

Commit 3159d6f

Browse files
committed
clean up jruby support
1 parent cfb5905 commit 3159d6f

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/reactive-ruby/server_rendering/contextual_renderer.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module ReactiveRuby
22
module ServerRendering
3-
def self.context_instance_var_name
4-
if RUBY_PLATFORM == 'java'
5-
'@rhino_context'
6-
else
7-
'@v8_context'
8-
end
3+
def self.context_instance_name
4+
return '@rhino_context' if RUBY_PLATFORM == 'java'
5+
'@v8_context'
6+
end
7+
8+
def self.context_instance_for(context)
9+
context.instance_variable_get(context_instance_name)
910
end
1011

1112
class ContextualRenderer < React::ServerRendering::SprocketsRenderer
@@ -15,9 +16,9 @@ def initialize(options = {})
1516
end
1617

1718
def render(component_name, props, prerender_options)
18-
if prerender_options.is_a? Hash
19+
if prerender_options.is_a?(Hash)
1920
if v8_runtime? && prerender_options[:context_initializer]
20-
raise React::ServerRendering::PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
21+
raise PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
2122
else
2223
prerender_options[:context_initializer].call v8_context
2324
prerender_options = prerender_options[:static] ? :static : true
@@ -30,10 +31,11 @@ def render(component_name, props, prerender_options)
3031
private
3132

3233
def v8_runtime?
33-
ExecJS.runtime.name == "(V8)" || ExecJS.runtime.name == "therubyrhino (Rhino)"
34+
["(V8)", "therubyrhino (Rhino)"].include?(ExecJS.runtime.name)
3435
end
36+
3537
def v8_context
36-
@v8_context ||= @context.instance_variable_get(ReactiveRuby::ServerRendering.context_instance_var_name)
38+
@v8_context ||= ReactiveRuby::ServerRendering.context_instance_for(@context)
3739
end
3840
end
3941
end

spec/reactive-ruby/component_loader_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
let(:js) { ::Rails.application.assets['components'].to_s }
1212
let(:context) { ExecJS.compile(GLOBAL_WRAPPER + js) }
13-
let(:v8_context) { context.instance_variable_get(ReactiveRuby::ServerRendering.context_instance_var_name) }
13+
let(:v8_context) { ReactiveRuby::ServerRendering.context_instance_for(context) }
1414

1515
describe '.new' do
1616
it 'raises a meaningful exception when initialized without a context' do

spec/reactive-ruby/isomorphic_helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_context(files = nil)
7373
end
7474
js = "#{React::ServerRendering::ExecJSRenderer::GLOBAL_WRAPPER}#{js}"
7575
ctx = ExecJS.compile(js)
76-
ctx = ctx.instance_variable_get(ReactiveRuby::ServerRendering.context_instance_var_name)
76+
ctx = ReactiveRuby::ServerRendering.context_instance_for(ctx)
7777
end
7878

7979
def react_context

0 commit comments

Comments
 (0)