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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8597a16d99c067226f1832565d36bf5c9021a4f5b54a1ee2cd23c1c6da4309a
4
- data.tar.gz: e712d0ebd4a43cf8e6311dfb1cf7b8dacdc1da3aed607f846f28fbd9a95c82dd
3
+ metadata.gz: dc03d863734914d6d34e16f357f6d5dfed20162c052e7c0725ad80c9b4582721
4
+ data.tar.gz: 7584c829f1e73a2cd274f6ff86076e682cfd945cc858a012c153a8a2eb2e78e0
5
5
  SHA512:
6
- metadata.gz: 46507c9416c5c04f684e4ceea2e7667c8c90976ded05c8ddb0e268b7420fc97bb1a41a2a37a57f5aa39d2b0ad5699d4ae74e3e93582251b56aa726c7ff30e497
7
- data.tar.gz: 5884fb376630de3ae0fe2100dd86dd59c38b9918f9beb79ce38339a43049aa897b353a3e3dfe2630575187786c5515efc94e02e0307e394934db69ee325ed225
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
- def self.mount!
4
- Isomorfeus.init
5
- on_ready do
6
- root_element = `document.querySelector('div[data-iso-root]')`
7
- component_name = root_element.JS.getAttribute('data-iso-root')
8
- Isomorfeus.env = root_element.JS.getAttribute('data-iso-env')
9
- begin
10
- component = component_name.constantize
11
- props_json = root_element.JS.getAttribute('data-iso-props')
12
- props = `Opal.Hash.$new(JSON.parse(props_json))`
13
- hydrated = root_element.JS.getAttribute('data-iso-hydrated')
14
- state_json = root_element.JS.getAttribute('data-iso-state')
15
- if state_json
16
- %x{
17
- var state = JSON.parse(state_json);
18
- var keys = Object.keys(state);
19
- for(var i=0; i < keys.length; i++) {
20
- global.Opal.Isomorfeus.store.native.dispatch({ type: keys[i].toUpperCase(), set_state: state[keys[i]] });
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
- def self.on_ready(&block)
33
- # this looks a bit odd but works across _all_ browsers, and no event handler mess
34
- %x{
35
- function run() { block.$call() };
36
- function ready_fun() {
37
- /in/.test(document.readyState) ? setTimeout(ready_fun,5) : run();
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
- def self.mount_component(component, props, element_or_query, hydrated = false)
52
- if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
53
- element = `document.body.querySelector(element_or_query)`
54
- elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
55
- element = element_or_query.to_n
56
- else
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
- Isomorfeus.top_component = if hydrated
61
- ReactDOM.hydrate(React.create_element(component, props), element)
62
- else
63
- ReactDOM.render(React.create_element(component, props), element)
64
- end
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
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.9.7'
2
+ VERSION = '16.9.8'
3
3
  end
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.7
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-21 00:00:00.000000000 Z
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj