isomorfeus-react 16.12.14 → 16.12.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/react_view_helper.rb +20 -8
- data/lib/isomorfeus/top_level_ssr.rb +15 -1
- data/lib/react/component/state.rb +2 -2
- data/lib/react/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c52d4071118b2aaf2dda6e7822a3954f9ce3ef2b4bdd846bd98d79658d0b35b3
|
4
|
+
data.tar.gz: 5e5aa6e03f9bd9e749ff9c8b096160c599d1c6402ee7ddbcf7afa1ebb3983ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb47191b1f7c54b62f87fdd57aee0bd5515587dccd3afd1253ace005abcf2cce17bc0072e37a32f71938c0c6e998cf765fb42dd0e2ec713dd2afd1ed68eb7ea
|
7
|
+
data.tar.gz: 9b2973a335e84430ef3e92063d92957fad546032037a0357d8cd6aa0cc9030de0504c022ac066f19fc5aac29959351c4c4f0f8a65c801e3c0da359e084e65736
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module ReactViewHelper
|
3
|
-
def cached_mount_component(component_name, props = {}, asset = 'application_ssr.js')
|
3
|
+
def cached_mount_component(component_name, props = {}, asset = 'application_ssr.js', static = false)
|
4
4
|
key = "#{component_name}#{props}#{asset}"
|
5
5
|
if Isomorfeus.production? && component_cache.key?(key)
|
6
6
|
render_result = component_cache[key][:render_result]
|
7
7
|
@ssr_response_status = component_cache[key][:ssr_response_status]
|
8
8
|
@sst_styles = component_cache[key][:ssr_styles]
|
9
9
|
else
|
10
|
-
render_result = mount_component(component_name, props, asset)
|
10
|
+
render_result = mount_component(component_name, props, asset, static)
|
11
11
|
status = ssr_response_status
|
12
12
|
if status >= 200 && status < 300
|
13
13
|
component_cache[key] = { render_result: render_result, ssr_response_status: status, ssr_styles: ssr_styles }
|
@@ -16,7 +16,11 @@ module Isomorfeus
|
|
16
16
|
render_result
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def cached_mount_static_component(component_name, props = {}, asset = 'application_ssr.js')
|
20
|
+
cached_mount_component(component_name, props, asset, true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mount_component(component_name, props = {}, asset = 'application_ssr.js', static = false)
|
20
24
|
@ssr_response_status = nil
|
21
25
|
@ssr_styles = nil
|
22
26
|
thread_id_asset = "#{Thread.current.object_id}#{asset}"
|
@@ -84,7 +88,8 @@ module Isomorfeus
|
|
84
88
|
global.Opal.Isomorfeus.TopLevel["$transport_ws_url="]("#{transport_ws_url}");
|
85
89
|
global.Opal.send(global.Opal.Isomorfeus.Transport.$promise_connect(), 'then', [], ($$1 = function(){
|
86
90
|
try {
|
87
|
-
global.Opal.Isomorfeus.TopLevel.$
|
91
|
+
if (#{static}) { global.Opal.Isomorfeus.TopLevel.$render_component_to_static_markup('#{component_name}', #{Oj.dump(props, mode: :strict)}); }
|
92
|
+
else { global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)}); }
|
88
93
|
global.FirstPassFinished = 'transport';
|
89
94
|
} catch (e) {
|
90
95
|
global.Exception = e;
|
@@ -142,7 +147,8 @@ module Isomorfeus
|
|
142
147
|
try {
|
143
148
|
let sheets = new global.Opal.global.MuiStyles.ServerStyleSheets();
|
144
149
|
let app = global.Opal.React.$create_element(component, global.Opal.Hash.$new(#{Oj.dump(props, mode: :strict)}));
|
145
|
-
rendered_tree = global.Opal.global.ReactDOMServer.
|
150
|
+
if (#{static}) { rendered_tree = global.Opal.global.ReactDOMServer.renderToStaticMarkup(sheets.collect(app)); }
|
151
|
+
else { rendered_tree = global.Opal.global.ReactDOMServer.renderToString(sheets.collect(app)); }
|
146
152
|
ssr_styles = sheets.toString();
|
147
153
|
} catch (e) {
|
148
154
|
global.Exception = e;
|
@@ -157,14 +163,16 @@ module Isomorfeus
|
|
157
163
|
let generate_id = global.Opal.global.ReactJSS.createGenerateId();
|
158
164
|
let app = global.Opal.React.$create_element(component, global.Opal.Hash.$new(#{Oj.dump(props, mode: :strict)}));
|
159
165
|
let element = global.Opal.global.React.createElement(global.Opal.global.ReactJSS.JssProvider, { registry: sheets, generateId: generate_id }, app);
|
160
|
-
rendered_tree = global.Opal.global.ReactDOMServer.
|
166
|
+
if (#{static}) { rendered_tree = global.Opal.global.ReactDOMServer.renderToStaticMarkup(element); }
|
167
|
+
else { rendered_tree = global.Opal.global.ReactDOMServer.renderToString(element); }
|
161
168
|
ssr_styles = sheets.toString();
|
162
169
|
} catch (e) {
|
163
170
|
global.Exception = e;
|
164
171
|
}
|
165
172
|
} else {
|
166
173
|
try {
|
167
|
-
rendered_tree = global.Opal.Isomorfeus.TopLevel.$
|
174
|
+
if (#{static}) { rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_static_markup('#{component_name}', #{Oj.dump(props, mode: :strict)}); }
|
175
|
+
else { rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)}); }
|
168
176
|
} catch (e) {
|
169
177
|
global.Exception = e;
|
170
178
|
}
|
@@ -176,7 +184,7 @@ module Isomorfeus
|
|
176
184
|
|
177
185
|
# execute second render pass
|
178
186
|
rendered_tree, application_state, @ssr_styles, @ssr_response_status, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
179
|
-
Isomorfeus.raise_error(message:
|
187
|
+
Isomorfeus.raise_error(message: exception['message'], stack: exception['stack']) if exception
|
180
188
|
|
181
189
|
# build result
|
182
190
|
render_result << " data-iso-hydrated='true'" if rendered_tree
|
@@ -192,6 +200,10 @@ module Isomorfeus
|
|
192
200
|
render_result
|
193
201
|
end
|
194
202
|
|
203
|
+
def mount_static_component(component_name, props = {}, asset = 'application_ssr.js')
|
204
|
+
mount_component(component_name, props, asset, true)
|
205
|
+
end
|
206
|
+
|
195
207
|
def ssr_response_status
|
196
208
|
@ssr_response_status || 200
|
197
209
|
end
|
@@ -8,7 +8,7 @@ module Isomorfeus
|
|
8
8
|
# nothing, but keep it for compatibility with browser
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def render_component_to_static_markup(component_name, props)
|
12
12
|
component = nil
|
13
13
|
%x{
|
14
14
|
if (typeof component_name === 'string' || component_name instanceof String) {
|
@@ -20,7 +20,21 @@ module Isomorfeus
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
component = Isomorfeus.cached_component_class(component_name) unless component
|
23
|
+
ReactDOMServer.render_to_static_markup(React.create_element(component, `Opal.Hash.$new(props)`))
|
24
|
+
end
|
23
25
|
|
26
|
+
def render_component_to_string(component_name, props)
|
27
|
+
component = nil
|
28
|
+
%x{
|
29
|
+
if (typeof component_name === 'string' || component_name instanceof String) {
|
30
|
+
component = component_name.split(".").reduce(function(o, x) {
|
31
|
+
return (o !== null && typeof o[x] !== "undefined" && o[x] !== null) ? o[x] : null;
|
32
|
+
}, Opal.global)
|
33
|
+
} else {
|
34
|
+
component = component_name;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
component = Isomorfeus.cached_component_class(component_name) unless component
|
24
38
|
ReactDOMServer.render_to_string(React.create_element(component, `Opal.Hash.$new(props)`))
|
25
39
|
end
|
26
40
|
end
|
@@ -20,8 +20,8 @@ module React
|
|
20
20
|
|
21
21
|
def set_state(updater, &block)
|
22
22
|
new_state = `{}`
|
23
|
-
updater.
|
24
|
-
new_state.JS[key] =
|
23
|
+
updater.each do |key, value|
|
24
|
+
new_state.JS[key] = value
|
25
25
|
end
|
26
26
|
if block_given?
|
27
27
|
@native.JS.setState(new_state, `function() { block.$call(); }`)
|
data/lib/react/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-react
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 16.12.
|
4
|
+
version: 16.12.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -277,7 +277,7 @@ metadata:
|
|
277
277
|
github_repo: ssh://github.com/isomorfeus/gems
|
278
278
|
post_install_message: |2+
|
279
279
|
|
280
|
-
isomorfeus-react 16.12.
|
280
|
+
isomorfeus-react 16.12.15:
|
281
281
|
Breaking change:
|
282
282
|
The event_handler DSL is gone. Instead use normal methods and method_ref, see:
|
283
283
|
https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/events.md
|