isomorfeus-react 16.9.7 → 16.9.8
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/lib/isomorfeus/react_view_helper.rb +5 -2
- data/lib/isomorfeus/top_level_browser.rb +61 -52
- data/lib/react/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc03d863734914d6d34e16f357f6d5dfed20162c052e7c0725ad80c9b4582721
|
|
4
|
+
data.tar.gz: 7584c829f1e73a2cd274f6ff86076e682cfd945cc858a012c153a8a2eb2e78e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c1814d751e1c9b0df44c0ec13f870111b81d4b93664437f565b80c02dc845b839d9a897c751500235306c01d0bd5474d795fdd228d1751e606510ed2f87be01
|
|
7
|
+
data.tar.gz: 64a2b50d8e0db1dfd519e781be3173d25f706321b98a2d7b4b99ae8f271839ba0bfc80b762145d3e9384664833fbe778f10b6bd128b011cbb6b0cf94a28828b5
|
|
@@ -17,6 +17,9 @@ module Isomorfeus
|
|
|
17
17
|
javascript = <<~JAVASCRIPT
|
|
18
18
|
global.FirstPassFinished = false;
|
|
19
19
|
global.Opal.Isomorfeus['$env=']('#{Isomorfeus.env}');
|
|
20
|
+
if (typeof global.Opal.Isomorfeus.$negotiated_locale === 'function') {
|
|
21
|
+
global.Opal.Isomorfeus["$negotiated_locale="]('#{props[:locale]}');
|
|
22
|
+
}
|
|
20
23
|
global.Opal.Isomorfeus['$force_init!']();
|
|
21
24
|
global.Opal.Isomorfeus['$ssr_response_status='](200);
|
|
22
25
|
global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');
|
|
@@ -81,10 +84,10 @@ module Isomorfeus
|
|
|
81
84
|
rendered_tree, application_state, @ssr_response_status = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
|
82
85
|
|
|
83
86
|
# build result
|
|
84
|
-
render_result << " data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
|
87
|
+
render_result << " data-iso-nloc='#{props[:locale]}' data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
|
85
88
|
render_result << rendered_tree
|
|
86
89
|
else
|
|
87
|
-
render_result << '>
|
|
90
|
+
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
|
88
91
|
end
|
|
89
92
|
render_result << '</div>'
|
|
90
93
|
render_result
|
|
@@ -1,67 +1,76 @@
|
|
|
1
1
|
module Isomorfeus
|
|
2
2
|
class TopLevel
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
component =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
class << self
|
|
4
|
+
def mount!
|
|
5
|
+
Isomorfeus.init
|
|
6
|
+
Isomorfeus::TopLevel.on_ready do
|
|
7
|
+
root_element = `document.querySelector('div[data-iso-root]')`
|
|
8
|
+
component_name = root_element.JS.getAttribute('data-iso-root')
|
|
9
|
+
Isomorfeus.env = root_element.JS.getAttribute('data-iso-env')
|
|
10
|
+
component = nil
|
|
11
|
+
begin
|
|
12
|
+
component = component_name.constantize
|
|
13
|
+
rescue
|
|
14
|
+
@timeout_start = Time.now unless @timeout_start
|
|
15
|
+
if (Time.now - @timeout_start) < 10
|
|
16
|
+
`setTimeout(Opal.Isomorfeus.TopLevel['$mount!'], 100)`
|
|
17
|
+
else
|
|
18
|
+
`console.error("Unable to mount '" + #{component_name} + "'!")`
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
if component
|
|
22
|
+
props_json = root_element.JS.getAttribute('data-iso-props')
|
|
23
|
+
props = `Opal.Hash.$new(JSON.parse(props_json))`
|
|
24
|
+
hydrated = root_element.JS.getAttribute('data-iso-hydrated')
|
|
25
|
+
state_json = root_element.JS.getAttribute('data-iso-state')
|
|
26
|
+
if state_json
|
|
27
|
+
%x{
|
|
28
|
+
var state = JSON.parse(state_json);
|
|
29
|
+
var keys = Object.keys(state);
|
|
30
|
+
for(var i=0; i < keys.length; i++) {
|
|
31
|
+
global.Opal.Isomorfeus.store.native.dispatch({ type: keys[i].toUpperCase(), set_state: state[keys[i]] });
|
|
32
|
+
}
|
|
21
33
|
}
|
|
22
|
-
|
|
34
|
+
end
|
|
35
|
+
mount_component(component, props, root_element, hydrated)
|
|
23
36
|
end
|
|
24
|
-
mount_component(component, props, root_element, hydrated)
|
|
25
|
-
rescue
|
|
26
|
-
@timeout_start = Time.now unless @timeout_start
|
|
27
|
-
`setTimeout(#{mount!}, 100)` if (Time.now - @timeout_start) < 10
|
|
28
37
|
end
|
|
29
38
|
end
|
|
30
|
-
end
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
def on_ready(&block)
|
|
41
|
+
# this looks a bit odd but works across _all_ browsers, and no event handler mess
|
|
42
|
+
%x{
|
|
43
|
+
function run() { block.$call() };
|
|
44
|
+
function ready_fun() {
|
|
45
|
+
/in/.test(document.readyState) ? setTimeout(ready_fun,5) : run();
|
|
46
|
+
}
|
|
47
|
+
ready_fun();
|
|
38
48
|
}
|
|
39
|
-
ready_fun();
|
|
40
|
-
}
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.on_ready_mount(component, props = nil, element_query = nil)
|
|
44
|
-
# init in case it hasn't been run yet
|
|
45
|
-
Isomorfeus.init
|
|
46
|
-
on_ready do
|
|
47
|
-
mount_component(component, props, element_query)
|
|
48
49
|
end
|
|
49
|
-
end
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
element = element_or_query
|
|
51
|
+
def on_ready_mount(component, props = nil, element_query = nil)
|
|
52
|
+
# init in case it hasn't been run yet
|
|
53
|
+
Isomorfeus.init
|
|
54
|
+
on_ready do
|
|
55
|
+
mount_component(component, props, element_query)
|
|
56
|
+
end
|
|
58
57
|
end
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
def mount_component(component, props, element_or_query, hydrated = false)
|
|
60
|
+
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
|
|
61
|
+
element = `document.body.querySelector(element_or_query)`
|
|
62
|
+
elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
|
|
63
|
+
element = element_or_query.to_n
|
|
64
|
+
else
|
|
65
|
+
element = element_or_query
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
Isomorfeus.top_component = if hydrated
|
|
69
|
+
ReactDOM.hydrate(React.create_element(component, props), element)
|
|
70
|
+
else
|
|
71
|
+
ReactDOM.render(React.create_element(component, props), element)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
65
74
|
end
|
|
66
75
|
end
|
|
67
76
|
end
|
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.9.
|
|
4
|
+
version: 16.9.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan Biedermann
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-08-
|
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oj
|