reactive-ruby 0.7.25 → 0.7.26
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 +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +22 -17
- data/README.md +1 -1
- data/Rakefile +12 -5
- data/example/examples/Gemfile.lock +1 -1
- data/example/rails-tutorial/Gemfile +2 -3
- data/example/rails-tutorial/Gemfile.lock +22 -23
- data/example/sinatra-tutorial/Gemfile.lock +4 -4
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +11 -0
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +14 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +6 -2
- data/lib/reactive-ruby.rb +3 -5
- data/lib/reactive-ruby/component_loader.rb +42 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +44 -71
- data/lib/reactive-ruby/rails.rb +7 -0
- data/lib/reactive-ruby/rails/component_mount.rb +44 -0
- data/lib/reactive-ruby/rails/controller_helper.rb +13 -0
- data/lib/reactive-ruby/rails/railtie.rb +14 -0
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +33 -0
- data/lib/reactive-ruby/version.rb +1 -1
- data/reactive-ruby.gemspec +1 -0
- data/spec/reactive-ruby/component_loader_spec.rb +58 -0
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +137 -0
- data/spec/{react/rails/view_helper_spec.rb → reactive-ruby/rails/component_mount_spec.rb} +15 -1
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +33 -0
- data/spec/spec_helper.rb +42 -19
- metadata +32 -5
- data/lib/rails-helpers/react_component.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea6849b4c9284445c1e8d1313fc53310f8758c7
|
4
|
+
data.tar.gz: f7082d055c5dcb39bf7a43187b2b9feb3105518f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 498495741c08b7e4f8928491c283c48d4e4eb0c9941ac95441013f1261bb6e1299346e26ee9d3df806b214782c8e34065d0c4805899f13b7f7aef4258f3c31c4
|
7
|
+
data.tar.gz: bce4a6ba733275e0bf39b61203a2c4878021038f88dd35b4e417e732dc7bf0f6b7f5c60a683360c2dee96d0dab9d9db9867f0da52ebd2771a50715a536ccd12e
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,7 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/catprintlabs/react-rails.git
|
3
|
-
revision: 98a8d903a51065c8e3ffedeb094d72a2e9883176
|
4
|
-
branch: isomorphic-methods-support
|
5
|
-
specs:
|
6
|
-
react-rails (1.0.0)
|
7
|
-
coffee-script-source (~> 1.8)
|
8
|
-
connection_pool
|
9
|
-
execjs
|
10
|
-
rails (>= 3.2)
|
11
|
-
tilt
|
12
|
-
|
13
1
|
PATH
|
14
2
|
remote: .
|
15
3
|
specs:
|
16
|
-
reactive-ruby (0.7.
|
4
|
+
reactive-ruby (0.7.25)
|
17
5
|
opal
|
18
6
|
opal-activesupport (>= 0.2.0)
|
19
7
|
opal-browser
|
@@ -57,6 +45,10 @@ GEM
|
|
57
45
|
thread_safe (~> 0.3, >= 0.3.4)
|
58
46
|
tzinfo (~> 1.1)
|
59
47
|
arel (6.0.3)
|
48
|
+
babel-source (5.8.26)
|
49
|
+
babel-transpiler (0.7.0)
|
50
|
+
babel-source (>= 4.0, < 6)
|
51
|
+
execjs (~> 2.0)
|
60
52
|
builder (3.2.2)
|
61
53
|
coffee-script-source (1.9.1.1)
|
62
54
|
connection_pool (2.2.0)
|
@@ -72,6 +64,7 @@ GEM
|
|
72
64
|
railties (>= 4.2.0)
|
73
65
|
thor (>= 0.14, < 2.0)
|
74
66
|
json (1.8.3)
|
67
|
+
libv8 (3.16.14.11)
|
75
68
|
loofah (2.0.3)
|
76
69
|
nokogiri (>= 1.5.9)
|
77
70
|
mail (2.6.3)
|
@@ -133,6 +126,14 @@ GEM
|
|
133
126
|
rake (>= 0.8.7)
|
134
127
|
thor (>= 0.18.1, < 2.0)
|
135
128
|
rake (10.4.2)
|
129
|
+
react-rails (1.3.1)
|
130
|
+
babel-transpiler (>= 0.7.0)
|
131
|
+
coffee-script-source (~> 1.8)
|
132
|
+
connection_pool
|
133
|
+
execjs
|
134
|
+
rails (>= 3.2)
|
135
|
+
tilt
|
136
|
+
ref (2.0.0)
|
136
137
|
rspec-core (3.3.2)
|
137
138
|
rspec-support (~> 3.3.0)
|
138
139
|
rspec-expectations (3.3.1)
|
@@ -162,9 +163,13 @@ GEM
|
|
162
163
|
activesupport (>= 3.0)
|
163
164
|
sprockets (>= 2.8, < 4.0)
|
164
165
|
sqlite3 (1.3.10)
|
166
|
+
therubyracer (0.12.2)
|
167
|
+
libv8 (~> 3.16.14.0)
|
168
|
+
ref
|
165
169
|
thor (0.19.1)
|
166
170
|
thread_safe (0.3.5)
|
167
171
|
tilt (2.0.1)
|
172
|
+
timecop (0.7.1)
|
168
173
|
tzinfo (1.2.2)
|
169
174
|
thread_safe (~> 0.1)
|
170
175
|
|
@@ -174,12 +179,12 @@ PLATFORMS
|
|
174
179
|
DEPENDENCIES
|
175
180
|
opal-rails
|
176
181
|
opal-rspec
|
182
|
+
rails
|
177
183
|
rake
|
178
|
-
react-rails
|
184
|
+
react-rails
|
179
185
|
reactive-ruby!
|
180
186
|
rspec-rails
|
181
187
|
sinatra
|
182
188
|
sqlite3
|
183
|
-
|
184
|
-
|
185
|
-
1.10.6
|
189
|
+
therubyracer
|
190
|
+
timecop
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -2,11 +2,16 @@ require 'bundler'
|
|
2
2
|
Bundler.require
|
3
3
|
Bundler::GemHelper.install_tasks
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
require 'opal/rspec/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new('ruby:rspec')
|
10
|
+
Opal::RSpec::RakeTask.new('opal:rspec')
|
11
|
+
|
12
|
+
task :test do
|
13
|
+
Rake::Task['ruby:rspec'].invoke
|
14
|
+
# Rake::Task['opal:rspec'].invoke
|
10
15
|
end
|
11
16
|
|
12
17
|
require 'generators/reactive_ruby/test_app/test_app_generator'
|
@@ -16,3 +21,5 @@ task :test_app do
|
|
16
21
|
puts "Setting up test app database..."
|
17
22
|
system("bundle exec rake db:drop db:create db:migrate > #{File::NULL}")
|
18
23
|
end
|
24
|
+
|
25
|
+
task default: [ :test ]
|
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'therubyracer', platforms: :ruby
|
4
|
-
gem 'react-rails'
|
5
|
-
gem 'opal-rails'
|
4
|
+
gem 'react-rails' #, git: "https://github.com/catprintlabs/react-rails.git", :branch => 'isomorphic-methods-support' # you need this branch of react-rails
|
5
|
+
gem 'opal-rails'
|
6
6
|
# integrates opal with sprockets etc
|
7
7
|
gem 'reactive-ruby', path: "../.."
|
8
8
|
|
@@ -48,4 +48,3 @@ group :development, :test do
|
|
48
48
|
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
49
49
|
gem 'spring'
|
50
50
|
end
|
51
|
-
|
@@ -1,21 +1,9 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://github.com/catprintlabs/react-rails.git
|
3
|
-
revision: 98a8d903a51065c8e3ffedeb094d72a2e9883176
|
4
|
-
branch: isomorphic-methods-support
|
5
|
-
specs:
|
6
|
-
react-rails (1.0.0)
|
7
|
-
coffee-script-source (~> 1.8)
|
8
|
-
connection_pool
|
9
|
-
execjs
|
10
|
-
rails (>= 3.2)
|
11
|
-
tilt
|
12
|
-
|
13
1
|
PATH
|
14
2
|
remote: ../..
|
15
3
|
specs:
|
16
|
-
reactive-ruby (0.7.
|
4
|
+
reactive-ruby (0.7.25)
|
17
5
|
opal
|
18
|
-
opal-activesupport
|
6
|
+
opal-activesupport (>= 0.2.0)
|
19
7
|
opal-browser
|
20
8
|
|
21
9
|
GEM
|
@@ -57,6 +45,10 @@ GEM
|
|
57
45
|
thread_safe (~> 0.3, >= 0.3.4)
|
58
46
|
tzinfo (~> 1.1)
|
59
47
|
arel (6.0.3)
|
48
|
+
babel-source (5.8.26)
|
49
|
+
babel-transpiler (0.7.0)
|
50
|
+
babel-source (>= 4.0, < 6)
|
51
|
+
execjs (~> 2.0)
|
60
52
|
binding_of_caller (0.7.2)
|
61
53
|
debug_inspector (>= 0.0.1)
|
62
54
|
builder (3.2.2)
|
@@ -89,18 +81,18 @@ GEM
|
|
89
81
|
nokogiri (>= 1.5.9)
|
90
82
|
mail (2.6.3)
|
91
83
|
mime-types (>= 1.16, < 3)
|
92
|
-
mime-types (2.6.
|
84
|
+
mime-types (2.6.2)
|
93
85
|
mini_portile (0.6.2)
|
94
|
-
minitest (5.8.
|
86
|
+
minitest (5.8.1)
|
95
87
|
multi_json (1.11.2)
|
96
88
|
nokogiri (1.6.6.2)
|
97
89
|
mini_portile (~> 0.6.0)
|
98
|
-
opal (0.8.
|
90
|
+
opal (0.8.1)
|
99
91
|
hike (~> 1.2)
|
100
92
|
sourcemap (~> 0.1.0)
|
101
93
|
sprockets (~> 3.1)
|
102
94
|
tilt (>= 1.4)
|
103
|
-
opal-activesupport (0.
|
95
|
+
opal-activesupport (0.2.0)
|
104
96
|
opal (>= 0.5.0, < 1.0.0)
|
105
97
|
opal-browser (0.2.0)
|
106
98
|
opal
|
@@ -116,7 +108,7 @@ GEM
|
|
116
108
|
rails (>= 3.2, < 5.0)
|
117
109
|
opal-rspec (0.4.3)
|
118
110
|
opal (>= 0.7.0, < 0.9)
|
119
|
-
paggio (0.2.
|
111
|
+
paggio (0.2.5)
|
120
112
|
rack (1.6.4)
|
121
113
|
rack-test (0.6.3)
|
122
114
|
rack (>= 1.0)
|
@@ -146,6 +138,13 @@ GEM
|
|
146
138
|
thor (>= 0.18.1, < 2.0)
|
147
139
|
rake (10.4.2)
|
148
140
|
rdoc (4.2.0)
|
141
|
+
react-rails (1.3.2)
|
142
|
+
babel-transpiler (>= 0.7.0)
|
143
|
+
coffee-script-source (~> 1.8)
|
144
|
+
connection_pool
|
145
|
+
execjs
|
146
|
+
rails (>= 3.2)
|
147
|
+
tilt
|
149
148
|
ref (2.0.0)
|
150
149
|
sass (3.4.18)
|
151
150
|
sass-rails (5.0.3)
|
@@ -159,9 +158,9 @@ GEM
|
|
159
158
|
rdoc (~> 4.0)
|
160
159
|
sourcemap (0.1.1)
|
161
160
|
spring (1.3.6)
|
162
|
-
sprockets (3.
|
163
|
-
rack (
|
164
|
-
sprockets-rails (2.3.
|
161
|
+
sprockets (3.4.0)
|
162
|
+
rack (> 1, < 3)
|
163
|
+
sprockets-rails (2.3.3)
|
165
164
|
actionpack (>= 3.0)
|
166
165
|
activesupport (>= 3.0)
|
167
166
|
sprockets (>= 2.8, < 4.0)
|
@@ -195,7 +194,7 @@ DEPENDENCIES
|
|
195
194
|
jquery-rails
|
196
195
|
opal-rails
|
197
196
|
rails (= 4.2.3)
|
198
|
-
react-rails
|
197
|
+
react-rails
|
199
198
|
reactive-ruby!
|
200
199
|
sass-rails (~> 5.0)
|
201
200
|
sdoc (~> 0.4.0)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
reactive-ruby (0.7.
|
4
|
+
reactive-ruby (0.7.25)
|
5
5
|
opal
|
6
|
-
opal-activesupport
|
6
|
+
opal-activesupport (>= 0.2.0)
|
7
7
|
opal-browser
|
8
8
|
|
9
9
|
GEM
|
@@ -15,14 +15,14 @@ GEM
|
|
15
15
|
sourcemap (~> 0.1.0)
|
16
16
|
sprockets (~> 3.1)
|
17
17
|
tilt (>= 1.4)
|
18
|
-
opal-activesupport (0.
|
18
|
+
opal-activesupport (0.2.0)
|
19
19
|
opal (>= 0.5.0, < 1.0.0)
|
20
20
|
opal-browser (0.2.0)
|
21
21
|
opal
|
22
22
|
paggio
|
23
23
|
opal-jquery (0.4.0)
|
24
24
|
opal (>= 0.7.0, < 0.9.0)
|
25
|
-
paggio (0.2.
|
25
|
+
paggio (0.2.5)
|
26
26
|
rack (1.6.4)
|
27
27
|
rack-protection (1.5.3)
|
28
28
|
rack
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails/generators/rails/app/app_generator'
|
2
2
|
|
3
3
|
module ReactiveRuby
|
4
|
-
class TestAppGenerator < Rails::Generators::Base
|
4
|
+
class TestAppGenerator < ::Rails::Generators::Base
|
5
5
|
def self.source_paths
|
6
6
|
paths = self.superclass.source_paths
|
7
7
|
paths << File.expand_path('../templates', __FILE__)
|
@@ -19,7 +19,7 @@ module ReactiveRuby
|
|
19
19
|
opts[:skip_bundle] = true
|
20
20
|
|
21
21
|
puts "Generating Test Rails Application..."
|
22
|
-
invoke Rails::Generators::AppGenerator,
|
22
|
+
invoke ::Rails::Generators::AppGenerator,
|
23
23
|
[ File.expand_path(test_app_path, destination_root) ], opts
|
24
24
|
end
|
25
25
|
|
@@ -30,6 +30,10 @@ module ReactiveRuby
|
|
30
30
|
"#{test_app_path}/app/assets/javascripts/application.rb", force: true
|
31
31
|
template 'assets/javascripts/components.rb',
|
32
32
|
"#{test_app_path}/app/views/components.rb", force: true
|
33
|
+
template 'views/components/hello_world.rb',
|
34
|
+
"#{test_app_path}/app/views/components/hello_world.rb", force: true
|
35
|
+
template 'views/components/todo.rb',
|
36
|
+
"#{test_app_path}/app/views/components/todo.rb", force: true
|
33
37
|
end
|
34
38
|
|
35
39
|
def clean_superfluous_files
|
data/lib/reactive-ruby.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
if RUBY_ENGINE == 'opal'
|
2
2
|
require "sources/react.js"
|
3
3
|
require "reactive-ruby/top_level"
|
4
|
-
require "reactive-ruby/component"
|
4
|
+
require "reactive-ruby/component"
|
5
5
|
require "reactive-ruby/element"
|
6
6
|
require "reactive-ruby/event"
|
7
7
|
require "reactive-ruby/version"
|
@@ -12,14 +12,12 @@ if RUBY_ENGINE == 'opal'
|
|
12
12
|
require "reactive-ruby/state"
|
13
13
|
require "reactive-ruby/isomorphic_helpers"
|
14
14
|
require "rails-helpers/top_level_rails_component"
|
15
|
-
|
16
15
|
else
|
17
16
|
require "opal"
|
18
|
-
require "opal-rails"
|
19
17
|
require "opal-browser"
|
20
|
-
require "reactive-ruby/version"
|
21
18
|
require "opal-activesupport"
|
22
|
-
require "
|
19
|
+
require "reactive-ruby/version"
|
20
|
+
require "reactive-ruby/rails" if defined?(Rails)
|
23
21
|
require "reactive-ruby/isomorphic_helpers"
|
24
22
|
require "reactive-ruby/serializers"
|
25
23
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ReactiveRuby
|
2
|
+
class ComponentLoader
|
3
|
+
attr_reader :v8_context
|
4
|
+
private :v8_context
|
5
|
+
|
6
|
+
def initialize(v8_context)
|
7
|
+
@v8_context = v8_context
|
8
|
+
end
|
9
|
+
|
10
|
+
def load(file = components)
|
11
|
+
return true if loaded?
|
12
|
+
!!v8_context.eval(opal(file))
|
13
|
+
end
|
14
|
+
|
15
|
+
def load!(file = components)
|
16
|
+
return true if loaded?
|
17
|
+
self.load(file)
|
18
|
+
ensure
|
19
|
+
raise "No react.rb components found in #{components}.rb" unless loaded?
|
20
|
+
end
|
21
|
+
|
22
|
+
def loaded?
|
23
|
+
!!v8_context.eval('Opal.React')
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def components
|
29
|
+
# Make this configurable at some point
|
30
|
+
'components'
|
31
|
+
end
|
32
|
+
|
33
|
+
def opal(file)
|
34
|
+
Opal::Processor.load_asset_code(assets, file)
|
35
|
+
rescue # What exception is being caught here?
|
36
|
+
end
|
37
|
+
|
38
|
+
def assets
|
39
|
+
::Rails.application.assets
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,21 +1,17 @@
|
|
1
1
|
module React
|
2
|
-
|
3
2
|
module IsomorphicHelpers
|
4
|
-
|
5
3
|
def self.included(base)
|
6
4
|
base.extend(ClassMethods)
|
7
5
|
end
|
8
|
-
|
6
|
+
|
9
7
|
if RUBY_ENGINE != 'opal'
|
10
|
-
|
11
8
|
def self.load_context(ctx, controller, name = nil)
|
12
9
|
puts "************************** React Server Context Initialized #{name} *********************************************"
|
13
|
-
@context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
|
10
|
+
@context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
|
14
11
|
end
|
15
|
-
|
16
12
|
else
|
17
|
-
|
18
|
-
|
13
|
+
def self.load_context(unique_id = nil, name = nil)
|
14
|
+
# can be called on the client to force re-initialization for testing purposes
|
19
15
|
if !unique_id or !@context or @context.unique_id != unique_id
|
20
16
|
if on_opal_server?
|
21
17
|
message = "************************ React Prerendering Context Initialized #{name} ***********************"
|
@@ -23,13 +19,12 @@ module React
|
|
23
19
|
message = "************************ React Browser Context Initialized ****************************"
|
24
20
|
end
|
25
21
|
log(message)
|
26
|
-
@context = Context.new(unique_id)
|
22
|
+
@context = Context.new(unique_id)
|
27
23
|
end
|
28
24
|
@context
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
|
-
|
27
|
+
|
33
28
|
def self.log(message, message_type = :info)
|
34
29
|
message = [message] unless message.is_a? Array
|
35
30
|
if message_type == :info
|
@@ -46,41 +41,37 @@ module React
|
|
46
41
|
`console.error.apply(console, message)`
|
47
42
|
end
|
48
43
|
end
|
49
|
-
|
44
|
+
|
50
45
|
if RUBY_ENGINE != 'opal'
|
51
|
-
|
52
46
|
def self.on_opal_server?
|
53
47
|
false
|
54
48
|
end
|
55
|
-
|
49
|
+
|
56
50
|
def self.on_opal_client?
|
57
51
|
false
|
58
52
|
end
|
59
|
-
|
60
53
|
else
|
61
|
-
|
62
54
|
def self.on_opal_server?
|
63
55
|
`typeof window.document === 'undefined'`
|
64
56
|
end
|
65
|
-
|
57
|
+
|
66
58
|
def self.on_opal_client?
|
67
59
|
!on_opal_server?
|
68
60
|
end
|
69
|
-
|
70
61
|
end
|
71
|
-
|
62
|
+
|
72
63
|
def log(*args)
|
73
64
|
IsomorphicHelpers.log(*args)
|
74
65
|
end
|
75
|
-
|
66
|
+
|
76
67
|
def on_opal_server?
|
77
|
-
|
68
|
+
self.class.on_opal_server?
|
78
69
|
end
|
79
|
-
|
70
|
+
|
80
71
|
def on_opal_client?
|
81
|
-
|
72
|
+
self.class.on_opal_client?
|
82
73
|
end
|
83
|
-
|
74
|
+
|
84
75
|
def self.prerender_footers
|
85
76
|
footer = Context.prerender_footer_blocks.collect { |block| block.call }.join("\n")
|
86
77
|
if RUBY_ENGINE != 'opal'
|
@@ -89,88 +80,78 @@ module React
|
|
89
80
|
end
|
90
81
|
footer
|
91
82
|
end
|
92
|
-
|
83
|
+
|
93
84
|
class Context
|
94
|
-
|
95
85
|
attr_reader :controller
|
96
86
|
attr_reader :unique_id
|
97
|
-
|
87
|
+
|
98
88
|
def self.before_first_mount_blocks
|
99
89
|
@before_first_mount_blocks ||= []
|
100
90
|
end
|
101
|
-
|
91
|
+
|
102
92
|
def self.prerender_footer_blocks
|
103
93
|
@prerender_footer_blocks ||= []
|
104
94
|
end
|
105
|
-
|
95
|
+
|
106
96
|
def initialize(unique_id, ctx = nil, controller = nil, name = nil)
|
107
97
|
@unique_id = unique_id
|
108
|
-
if RUBY_ENGINE != 'opal'
|
98
|
+
if RUBY_ENGINE != 'opal'
|
109
99
|
@controller = controller
|
110
|
-
@ctx = ctx
|
100
|
+
@ctx = ctx
|
111
101
|
ctx["ServerSideIsomorphicMethods"] = self
|
112
102
|
send_to_opal(:load_context, @unique_id, name)
|
113
103
|
end
|
114
|
-
self.class.before_first_mount_blocks.each { |block| block.call(self) }
|
104
|
+
self.class.before_first_mount_blocks.each { |block| block.call(self) }
|
115
105
|
end
|
116
|
-
|
106
|
+
|
117
107
|
def eval(js)
|
118
108
|
@ctx.eval(js) if @ctx
|
119
109
|
end
|
120
|
-
|
110
|
+
|
121
111
|
def send_to_opal(method, *args)
|
112
|
+
return unless @ctx
|
122
113
|
args = [1] if args.length == 0
|
123
|
-
|
124
|
-
|
125
|
-
@ctx.eval(Opal::Processor.load_asset_code(::Rails.application.assets, 'components')) rescue nil
|
126
|
-
raise "No opal-react components found in the components.rb file" unless @ctx.eval('Opal.React')
|
127
|
-
end
|
128
|
-
@ctx.eval("Opal.React.IsomorphicHelpers.$#{method}(#{args.collect { |arg| "'#{arg}'"}.join(', ')})")
|
129
|
-
end
|
114
|
+
::ReactiveRuby::ComponentLoader.new(@ctx).load!
|
115
|
+
@ctx.eval("Opal.React.IsomorphicHelpers.$#{method}(#{args.collect { |arg| "'#{arg}'"}.join(', ')})")
|
130
116
|
end
|
131
|
-
|
117
|
+
|
132
118
|
def self.register_before_first_mount_block(&block)
|
133
119
|
before_first_mount_blocks << block
|
134
120
|
end
|
135
|
-
|
121
|
+
|
136
122
|
def self.register_prerender_footer_block(&block)
|
137
123
|
prerender_footer_blocks << block
|
138
124
|
end
|
139
|
-
|
140
125
|
end
|
141
|
-
|
126
|
+
|
142
127
|
class IsomorphicProcCall
|
143
|
-
|
144
128
|
def result
|
145
129
|
@result.first if @result
|
146
130
|
end
|
147
|
-
|
131
|
+
|
148
132
|
def initialize(name, block, *args)
|
149
133
|
@name = name
|
150
134
|
block.call(self, *args)
|
151
135
|
@result ||= send_to_server(*args) if IsomorphicHelpers.on_opal_server?
|
152
136
|
end
|
153
|
-
|
137
|
+
|
154
138
|
def when_on_client(&block)
|
155
139
|
@result = [block.call] if IsomorphicHelpers.on_opal_client?
|
156
140
|
end
|
157
|
-
|
158
|
-
def send_to_server(*args)
|
141
|
+
|
142
|
+
def send_to_server(*args)
|
159
143
|
if IsomorphicHelpers.on_opal_server?
|
160
144
|
args_as_json = args.to_json
|
161
|
-
@result = [JSON.parse(`window.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)]
|
145
|
+
@result = [JSON.parse(`window.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)]
|
162
146
|
end
|
163
147
|
end
|
164
|
-
|
148
|
+
|
165
149
|
def when_on_server(&block)
|
166
150
|
@result = [block.call.to_json] unless IsomorphicHelpers.on_opal_client? or IsomorphicHelpers.on_opal_server?
|
167
151
|
end
|
168
|
-
|
169
152
|
end
|
170
|
-
|
171
|
-
|
153
|
+
|
172
154
|
module ClassMethods
|
173
|
-
|
174
155
|
def on_opal_server?
|
175
156
|
IsomorphicHelpers.on_opal_server?
|
176
157
|
end
|
@@ -178,46 +159,38 @@ module React
|
|
178
159
|
def on_opal_client?
|
179
160
|
IsomorphicHelpers.on_opal_client?
|
180
161
|
end
|
181
|
-
|
162
|
+
|
182
163
|
def log(*args)
|
183
164
|
IsomorphicHelpers.log(*args)
|
184
165
|
end
|
185
|
-
|
166
|
+
|
186
167
|
def controller
|
187
168
|
IsomorphicHelpers.context.controller
|
188
169
|
end
|
189
|
-
|
170
|
+
|
190
171
|
def before_first_mount(&block)
|
191
172
|
React::IsomorphicHelpers::Context.register_before_first_mount_block &block
|
192
173
|
end
|
193
|
-
|
174
|
+
|
194
175
|
def prerender_footer(&block)
|
195
176
|
React::IsomorphicHelpers::Context.register_prerender_footer_block &block
|
196
177
|
end
|
197
|
-
|
178
|
+
|
198
179
|
if RUBY_ENGINE != 'opal'
|
199
|
-
|
200
180
|
def isomorphic_method(name, &block)
|
201
181
|
React::IsomorphicHelpers::Context.send(:define_method, name) do |args_as_json|
|
202
182
|
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, *JSON.parse(args_as_json)).result
|
203
183
|
end
|
204
184
|
end
|
205
|
-
|
206
185
|
else
|
207
|
-
|
208
186
|
require 'json'
|
209
|
-
|
187
|
+
|
210
188
|
def isomorphic_method(name, &block)
|
211
189
|
self.class.send(:define_method, name) do | *args |
|
212
190
|
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, *args).result
|
213
191
|
end
|
214
192
|
end
|
215
|
-
|
216
193
|
end
|
217
|
-
|
218
|
-
|
219
194
|
end
|
220
|
-
|
221
195
|
end
|
222
|
-
|
223
|
-
end
|
196
|
+
end
|