hyper-react 0.12.7 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +48 -34
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -6
- data/README.md +47 -98
- data/Rakefile +6 -28
- data/hyper-react.gemspec +36 -43
- data/lib/hyper-react.rb +4 -73
- data/lib/react/version.rb +3 -0
- metadata +91 -249
- data/.codeclimate.yml +0 -27
- data/.rubocop.yml +0 -1159
- data/.travis.yml +0 -62
- data/Appraisals +0 -31
- data/CHANGELOG.md +0 -143
- data/LICENSE +0 -19
- data/UPGRADING.md +0 -24
- data/component-name-lookup.md +0 -145
- data/config.ru +0 -26
- data/gemfiles/opal_0.10_react_13.gemfile +0 -15
- data/gemfiles/opal_0.10_react_14.gemfile +0 -15
- data/gemfiles/opal_0.10_react_15.gemfile +0 -15
- data/gemfiles/opal_0.8_react_13.gemfile +0 -15
- data/gemfiles/opal_0.8_react_14.gemfile +0 -15
- data/gemfiles/opal_0.8_react_15.gemfile +0 -15
- data/gemfiles/opal_0.9_react_13.gemfile +0 -15
- data/gemfiles/opal_0.9_react_14.gemfile +0 -15
- data/gemfiles/opal_0.9_react_15.gemfile +0 -15
- data/gemfiles/opal_master_react_15.gemfile +0 -16
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
- data/lib/rails-helpers/top_level_rails_component.rb +0 -54
- data/lib/react-sources/react-server.js +0 -2
- data/lib/react/api.rb +0 -173
- data/lib/react/callbacks.rb +0 -41
- data/lib/react/children.rb +0 -30
- data/lib/react/component.rb +0 -168
- data/lib/react/component/api.rb +0 -50
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -189
- data/lib/react/component/dsl_instance_methods.rb +0 -23
- data/lib/react/component/params.rb +0 -6
- data/lib/react/component/props_wrapper.rb +0 -78
- data/lib/react/component/should_component_update.rb +0 -94
- data/lib/react/component/tags.rb +0 -129
- data/lib/react/config.rb +0 -5
- data/lib/react/config/client.rb.erb +0 -19
- data/lib/react/config/server.rb +0 -23
- data/lib/react/element.rb +0 -169
- data/lib/react/event.rb +0 -76
- data/lib/react/ext/hash.rb +0 -9
- data/lib/react/ext/opal-jquery/element.rb +0 -26
- data/lib/react/ext/string.rb +0 -8
- data/lib/react/hash.rb +0 -13
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/react-source-browser.rb +0 -3
- data/lib/react/react-source-server.rb +0 -3
- data/lib/react/react-source.rb +0 -20
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -144
- data/lib/react/server.rb +0 -23
- data/lib/react/state_wrapper.rb +0 -23
- data/lib/react/test.rb +0 -16
- data/lib/react/test/dsl.rb +0 -17
- data/lib/react/test/matchers/render_html_matcher.rb +0 -56
- data/lib/react/test/rspec.rb +0 -15
- data/lib/react/test/session.rb +0 -37
- data/lib/react/test/utils.rb +0 -25
- data/lib/react/top_level.rb +0 -118
- data/lib/react/top_level_render.rb +0 -29
- data/lib/react/validator.rb +0 -136
- data/lib/reactive-ruby/component_loader.rb +0 -50
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
- data/lib/reactive-ruby/rails.rb +0 -7
- data/lib/reactive-ruby/rails/component_mount.rb +0 -46
- data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
- data/lib/reactive-ruby/rails/railtie.rb +0 -33
- data/lib/reactive-ruby/serializers.rb +0 -15
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
- data/lib/reactive-ruby/version.rb +0 -3
- data/lib/reactrb/auto-import.rb +0 -27
- data/lib/reactrb/deep-compare.rb +0 -24
- data/lib/reactrb/new-event-name-convention.rb +0 -11
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +0 -9
- data/spec/controller_helper_spec.rb +0 -34
- data/spec/index.html.erb +0 -11
- data/spec/react/callbacks_spec.rb +0 -138
- data/spec/react/children_spec.rb +0 -76
- data/spec/react/component/base_spec.rb +0 -32
- data/spec/react/component_spec.rb +0 -884
- data/spec/react/dsl_spec.rb +0 -303
- data/spec/react/element_spec.rb +0 -136
- data/spec/react/event_spec.rb +0 -24
- data/spec/react/native_library_spec.rb +0 -322
- data/spec/react/observable_spec.rb +0 -42
- data/spec/react/opal_jquery_extensions_spec.rb +0 -68
- data/spec/react/param_declaration_spec.rb +0 -269
- data/spec/react/react_spec.rb +0 -215
- data/spec/react/refs_callback_spec.rb +0 -56
- data/spec/react/server_spec.rb +0 -25
- data/spec/react/state_spec.rb +0 -55
- data/spec/react/test/dsl_spec.rb +0 -43
- data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
- data/spec/react/test/rspec_spec.rb +0 -62
- data/spec/react/test/session_spec.rb +0 -88
- data/spec/react/test/utils_spec.rb +0 -28
- data/spec/react/top_level_component_spec.rb +0 -101
- data/spec/react/tutorial/tutorial_spec.rb +0 -36
- data/spec/react/validator_spec.rb +0 -124
- data/spec/reactive-ruby/component_loader_spec.rb +0 -77
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
- data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -149
- data/spec/support/react/spec_helpers.rb +0 -44
- data/spec/vendor/es5-shim.min.js +0 -6
- data/spec/vendor/jquery-2.2.4.min.js +0 -4
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module ReactiveRuby
|
|
2
|
-
class ComponentLoader
|
|
3
|
-
attr_reader :v8_context
|
|
4
|
-
private :v8_context
|
|
5
|
-
|
|
6
|
-
def initialize(v8_context)
|
|
7
|
-
unless v8_context
|
|
8
|
-
raise ArgumentError.new('Could not obtain ExecJS runtime context')
|
|
9
|
-
end
|
|
10
|
-
@v8_context = v8_context
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def load(file = components)
|
|
14
|
-
return true if loaded?
|
|
15
|
-
!!v8_context.eval(opal(file))
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def load!(file = components)
|
|
19
|
-
return true if loaded?
|
|
20
|
-
self.load(file)
|
|
21
|
-
ensure
|
|
22
|
-
raise "No react.rb components found in #{components}.rb" unless loaded?
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def loaded?
|
|
26
|
-
!!v8_context.eval('Opal.React')
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def components
|
|
32
|
-
opts = ::Rails.configuration.react.server_renderer_options
|
|
33
|
-
return opts[:files].first.gsub(/.js$/,'') if opts && opts[:files]
|
|
34
|
-
'components'
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def opal(file)
|
|
38
|
-
if Opal::Processor.respond_to?(:load_asset_code)
|
|
39
|
-
Opal::Processor.load_asset_code(assets, file)
|
|
40
|
-
else
|
|
41
|
-
Opal::Sprockets.load_asset(file, assets)
|
|
42
|
-
end
|
|
43
|
-
rescue # What exception is being caught here?
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def assets
|
|
47
|
-
::Rails.application.assets
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
require "react/config"
|
|
2
|
-
|
|
3
|
-
module React
|
|
4
|
-
module IsomorphicHelpers
|
|
5
|
-
def self.included(base)
|
|
6
|
-
base.extend(ClassMethods)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
if RUBY_ENGINE != 'opal'
|
|
10
|
-
def self.load_context(ctx, controller, name = nil)
|
|
11
|
-
puts "************************** React Server Context Initialized #{name} *********************************************"
|
|
12
|
-
@context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
|
|
13
|
-
end
|
|
14
|
-
else
|
|
15
|
-
def self.load_context(unique_id = nil, name = nil)
|
|
16
|
-
# can be called on the client to force re-initialization for testing purposes
|
|
17
|
-
if !unique_id || !@context || @context.unique_id != unique_id
|
|
18
|
-
if on_opal_server?
|
|
19
|
-
`console.history = []` rescue nil
|
|
20
|
-
message = "************************ React Prerendering Context Initialized #{name} ***********************"
|
|
21
|
-
else
|
|
22
|
-
message = "************************ React Browser Context Initialized ****************************"
|
|
23
|
-
end
|
|
24
|
-
log(message)
|
|
25
|
-
@context = Context.new(unique_id)
|
|
26
|
-
end
|
|
27
|
-
@context
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def self.log(message, message_type = :info)
|
|
32
|
-
message = [message] unless message.is_a? Array
|
|
33
|
-
|
|
34
|
-
is_production = React::Config.config[:environment] == 'production'
|
|
35
|
-
|
|
36
|
-
if (message_type == :info || message_type == :warning) && is_production
|
|
37
|
-
return
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
if message_type == :info
|
|
41
|
-
if on_opal_server?
|
|
42
|
-
style = 'background: #00FFFF; color: red'
|
|
43
|
-
else
|
|
44
|
-
style = 'background: #222; color: #bada55'
|
|
45
|
-
end
|
|
46
|
-
message = ["%c" + message[0], style]+message[1..-1]
|
|
47
|
-
`console.log.apply(console, message)`
|
|
48
|
-
elsif message_type == :warning
|
|
49
|
-
`console.warn.apply(console, message)`
|
|
50
|
-
else
|
|
51
|
-
`console.error.apply(console, message)`
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
if RUBY_ENGINE != 'opal'
|
|
56
|
-
def self.on_opal_server?
|
|
57
|
-
false
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.on_opal_client?
|
|
61
|
-
false
|
|
62
|
-
end
|
|
63
|
-
else
|
|
64
|
-
def self.on_opal_server?
|
|
65
|
-
`typeof Opal.global.document === 'undefined'`
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def self.on_opal_client?
|
|
69
|
-
!on_opal_server?
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def log(*args)
|
|
74
|
-
IsomorphicHelpers.log(*args)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def on_opal_server?
|
|
78
|
-
self.class.on_opal_server?
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def on_opal_client?
|
|
82
|
-
self.class.on_opal_client?
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def self.prerender_footers(controller = nil)
|
|
86
|
-
footer = Context.prerender_footer_blocks.collect { |block| block.call controller }.join("\n")
|
|
87
|
-
if RUBY_ENGINE != 'opal'
|
|
88
|
-
footer = (footer + @context.send_to_opal(:prerender_footers).to_s) if @context
|
|
89
|
-
footer = footer.html_safe
|
|
90
|
-
end
|
|
91
|
-
footer
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
class Context
|
|
95
|
-
attr_reader :controller
|
|
96
|
-
attr_reader :unique_id
|
|
97
|
-
|
|
98
|
-
def self.before_first_mount_blocks
|
|
99
|
-
@before_first_mount_blocks ||= []
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.prerender_footer_blocks
|
|
103
|
-
@prerender_footer_blocks ||= []
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def initialize(unique_id, ctx = nil, controller = nil, name = nil)
|
|
107
|
-
@unique_id = unique_id
|
|
108
|
-
if RUBY_ENGINE != 'opal'
|
|
109
|
-
@controller = controller
|
|
110
|
-
@ctx = ctx
|
|
111
|
-
ctx["ServerSideIsomorphicMethods"] = self
|
|
112
|
-
send_to_opal(:load_context, @unique_id, name)
|
|
113
|
-
end
|
|
114
|
-
Hyperloop::Application::Boot.run(context: self)
|
|
115
|
-
self.class.before_first_mount_blocks.each { |block| block.call(self) }
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def eval(js)
|
|
119
|
-
@ctx.eval(js) if @ctx
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def send_to_opal(method, *args)
|
|
123
|
-
return unless @ctx
|
|
124
|
-
args = [1] if args.length == 0
|
|
125
|
-
::ReactiveRuby::ComponentLoader.new(@ctx).load!
|
|
126
|
-
@ctx.eval("Opal.React.$const_get('IsomorphicHelpers').$#{method}(#{args.collect { |arg| "'#{arg}'"}.join(', ')})")
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def self.register_before_first_mount_block(&block)
|
|
130
|
-
before_first_mount_blocks << block
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def self.register_prerender_footer_block(&block)
|
|
134
|
-
prerender_footer_blocks << block
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
class IsomorphicProcCall
|
|
139
|
-
|
|
140
|
-
attr_reader :context
|
|
141
|
-
|
|
142
|
-
def result
|
|
143
|
-
@result.first if @result
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def initialize(name, block, context, *args)
|
|
147
|
-
@name = name
|
|
148
|
-
@context = context
|
|
149
|
-
block.call(self, *args)
|
|
150
|
-
@result ||= send_to_server(*args) if IsomorphicHelpers.on_opal_server?
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def when_on_client(&block)
|
|
154
|
-
@result = [block.call] if IsomorphicHelpers.on_opal_client?
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def send_to_server(*args)
|
|
158
|
-
if IsomorphicHelpers.on_opal_server?
|
|
159
|
-
args_as_json = args.to_json
|
|
160
|
-
@result = [JSON.parse(`Opal.global.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)]
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def when_on_server(&block)
|
|
165
|
-
@result = [block.call.to_json] unless IsomorphicHelpers.on_opal_client? || IsomorphicHelpers.on_opal_server?
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
module ClassMethods
|
|
170
|
-
def on_opal_server?
|
|
171
|
-
IsomorphicHelpers.on_opal_server?
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def on_opal_client?
|
|
175
|
-
IsomorphicHelpers.on_opal_client?
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def log(*args)
|
|
179
|
-
IsomorphicHelpers.log(*args)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def controller
|
|
183
|
-
IsomorphicHelpers.context.controller
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def before_first_mount(&block)
|
|
187
|
-
React::IsomorphicHelpers::Context.register_before_first_mount_block &block
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def prerender_footer(&block)
|
|
191
|
-
React::IsomorphicHelpers::Context.register_prerender_footer_block &block
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
if RUBY_ENGINE != 'opal'
|
|
195
|
-
def isomorphic_method(name, &block)
|
|
196
|
-
React::IsomorphicHelpers::Context.send(:define_method, name) do |args_as_json|
|
|
197
|
-
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, self, *JSON.parse(args_as_json)).result
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
else
|
|
201
|
-
require 'json'
|
|
202
|
-
|
|
203
|
-
def isomorphic_method(name, &block)
|
|
204
|
-
self.class.send(:define_method, name) do | *args |
|
|
205
|
-
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, self, *args).result
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|
data/lib/reactive-ruby/rails.rb
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
require 'action_view'
|
|
2
|
-
require 'react-rails'
|
|
3
|
-
require 'reactive-ruby/server_rendering/contextual_renderer'
|
|
4
|
-
require 'reactive-ruby/rails/component_mount'
|
|
5
|
-
require 'reactive-ruby/rails/railtie'
|
|
6
|
-
require 'reactive-ruby/rails/controller_helper'
|
|
7
|
-
require 'reactive-ruby/component_loader'
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module ReactiveRuby
|
|
2
|
-
module Rails
|
|
3
|
-
class ComponentMount < React::Rails::ComponentMount
|
|
4
|
-
attr_accessor :controller
|
|
5
|
-
|
|
6
|
-
def setup(controller)
|
|
7
|
-
self.controller = controller
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def react_component(name, props = {}, options = {}, &block)
|
|
11
|
-
options = context_initializer_options(options, name) if options[:prerender]
|
|
12
|
-
props = serialized_props(props, name, controller)
|
|
13
|
-
super(top_level_name, props, options, &block).gsub("\n","")
|
|
14
|
-
.gsub(/(<script>.*<\/script>)<\/div>$/,'</div>\1').html_safe +
|
|
15
|
-
footers
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def context_initializer_options(options, name)
|
|
21
|
-
options[:prerender] = {options[:prerender] => true} unless options[:prerender].is_a? Hash
|
|
22
|
-
existing_context_initializer = options[:prerender][:context_initializer]
|
|
23
|
-
|
|
24
|
-
options[:prerender][:context_initializer] = lambda do |ctx|
|
|
25
|
-
React::IsomorphicHelpers.load_context(ctx, controller, name)
|
|
26
|
-
existing_context_initializer.call ctx if existing_context_initializer
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
options
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def serialized_props(props, name, controller)
|
|
33
|
-
{ render_params: props, component_name: name,
|
|
34
|
-
controller: controller.class.name.gsub(/Controller$/,"") }.react_serializer
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def top_level_name
|
|
38
|
-
'React.TopLevelRailsComponent'
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def footers
|
|
42
|
-
React::IsomorphicHelpers.prerender_footers(controller)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'action_controller'
|
|
2
|
-
|
|
3
|
-
module ActionController
|
|
4
|
-
# adds render_component helper to ActionControllers
|
|
5
|
-
class Base
|
|
6
|
-
def render_component(*args)
|
|
7
|
-
@component_name = (args[0].is_a? Hash) || args.empty? ? params[:action].camelize : args.shift
|
|
8
|
-
@render_params = args.shift || {}
|
|
9
|
-
options = args[0] || {}
|
|
10
|
-
render inline: '<%= react_component @component_name, @render_params, '\
|
|
11
|
-
'{ prerender: !params[:no_prerender] } %>',
|
|
12
|
-
layout: options.key?(:layout) ? options[:layout].to_s : :default
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module ReactiveRuby
|
|
2
|
-
module Rails
|
|
3
|
-
class Railtie < ::Rails::Railtie
|
|
4
|
-
config.before_configuration do |app|
|
|
5
|
-
app.config.assets.enabled = true
|
|
6
|
-
app.config.assets.paths << ::Rails.root.join('app', 'views').to_s
|
|
7
|
-
app.config.react.server_renderer =
|
|
8
|
-
ReactiveRuby::ServerRendering::ContextualRenderer
|
|
9
|
-
app.config.react.view_helper_implementation =
|
|
10
|
-
ReactiveRuby::Rails::ComponentMount
|
|
11
|
-
end
|
|
12
|
-
config.after_initialize do
|
|
13
|
-
::ApplicationController.class_eval do
|
|
14
|
-
before_action do
|
|
15
|
-
if params.has_key? 'hyperloop-prerendering'
|
|
16
|
-
params['hyperloop-prerendering'].to_s == 'on'
|
|
17
|
-
elsif params.has_key? 'hyperloop_prerendering'
|
|
18
|
-
params['hyperloop_prerendering'].to_s == 'on'
|
|
19
|
-
else
|
|
20
|
-
Hyperloop.prerendering.to_s == 'on'
|
|
21
|
-
end && next
|
|
22
|
-
params[:no_prerender] = '1'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
class ::HyperloopController < ::ApplicationController
|
|
26
|
-
def action_missing(name)
|
|
27
|
-
render_component
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
[Bignum, FalseClass, Fixnum, Float, Integer, NilClass, String, Symbol, Time, TrueClass].each do |klass|
|
|
2
|
-
klass.send(:define_method, :react_serializer) do
|
|
3
|
-
as_json
|
|
4
|
-
end
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
BigDecimal.send(:define_method, :react_serializer) { as_json } rescue nil
|
|
8
|
-
|
|
9
|
-
Array.send(:define_method, :react_serializer) do
|
|
10
|
-
self.collect { |e| e.react_serializer }.as_json
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Hash.send(:define_method, :react_serializer) do
|
|
14
|
-
Hash[*self.collect { |key, value| [key, value.react_serializer] }.flatten(1)].as_json
|
|
15
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module ReactiveRuby
|
|
2
|
-
module ServerRendering
|
|
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)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class ContextualRenderer < React::ServerRendering::SprocketsRenderer
|
|
13
|
-
def initialize(options = {})
|
|
14
|
-
super(options)
|
|
15
|
-
ComponentLoader.new(v8_context).load
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def render(component_name, props, prerender_options)
|
|
19
|
-
if prerender_options.is_a?(Hash)
|
|
20
|
-
if v8_runtime? && prerender_options[:context_initializer]
|
|
21
|
-
raise PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
|
|
22
|
-
else
|
|
23
|
-
prerender_options[:context_initializer].call v8_context
|
|
24
|
-
prerender_options = prerender_options[:static] ? :static : true
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
super(component_name, props, prerender_options)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def v8_runtime?
|
|
34
|
-
["(V8)", "therubyrhino (Rhino)"].include?(ExecJS.runtime.name)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def v8_context
|
|
38
|
-
@v8_context ||= ReactiveRuby::ServerRendering.context_instance_for(@context)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
data/lib/reactrb/auto-import.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# rubocop:disable Style/FileName
|
|
2
|
-
# require 'reactrb/auto-import' to automatically
|
|
3
|
-
# import JS libraries and components when they are detected
|
|
4
|
-
if RUBY_ENGINE == 'opal'
|
|
5
|
-
# modifies const and method_missing so that they will attempt
|
|
6
|
-
# to auto import native libraries and components using React::NativeLibrary
|
|
7
|
-
class Object
|
|
8
|
-
class << self
|
|
9
|
-
alias _reactrb_original_const_missing const_missing
|
|
10
|
-
alias _reactrb_original_method_missing method_missing
|
|
11
|
-
|
|
12
|
-
def const_missing(const_name)
|
|
13
|
-
# Opal uses const_missing to initially define things,
|
|
14
|
-
# so we always call the original, and respond to the exception
|
|
15
|
-
_reactrb_original_const_missing(const_name)
|
|
16
|
-
rescue StandardError => e
|
|
17
|
-
React::NativeLibrary.import_const_from_native(Object, const_name, true) || raise(e)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def method_missing(method, *args, &block)
|
|
21
|
-
component_class = React::NativeLibrary.import_const_from_native(self, method, false)
|
|
22
|
-
_reactrb_original_method_missing(method, *args, &block) unless component_class
|
|
23
|
-
React::RenderingContext.render(component_class, *args, &block)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|