isomorfeus-react 16.12.3 → 16.12.4
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/config.rb +11 -0
- data/lib/isomorfeus/react_view_helper.rb +26 -2
- data/lib/isomorfeus/top_level.rb +11 -8
- data/lib/lucid_app/native_lucid_component_constructor.rb +2 -1
- data/lib/lucid_component/native_lucid_component_constructor.rb +2 -5
- data/lib/lucid_component/preloading_support.rb +13 -20
- data/lib/lucid_material/func/native_component_constructor.rb +5 -5
- data/lib/react/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69771dea65edc7607119f666d42f3b94e9127086ad3e030c471856102309257e
|
4
|
+
data.tar.gz: 7c2c7490ada522852b4afb23031a82fa819f772d46e68f39829d5b35de22164b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e1c4ed99f44f8bb592da6cf0b0e9b20b24ccc435533b32dfff6239418528161387395056870fad6114f22ea9a36a3f88b9380b6900d477c59cd1289ec14153
|
7
|
+
data.tar.gz: 7b6b021c7a543befab9c9999e13938b4e02d401f357b556d1d4d40494b90c2fef26c7e8b58da9ea0300e6733070d8b8e2646ca1c146f94fb75f6a67af5ccf95d
|
data/lib/isomorfeus/config.rb
CHANGED
@@ -28,6 +28,10 @@ module Isomorfeus
|
|
28
28
|
client_init_class_names << init_class_name
|
29
29
|
end
|
30
30
|
|
31
|
+
def add_client_init_after_store_class_name(init_class_name)
|
32
|
+
client_init_after_store_class_names << init_class_name
|
33
|
+
end
|
34
|
+
|
31
35
|
def add_client_option(key, value = nil)
|
32
36
|
self.class.attr_accessor(key)
|
33
37
|
self.send("#{key}=", value)
|
@@ -50,6 +54,12 @@ module Isomorfeus
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
def execute_init_after_store_classes
|
58
|
+
client_init_after_store_class_names.each do |constant|
|
59
|
+
constant.constantize.send(:init)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
def env=(env_string)
|
54
64
|
@env = env_string ? env_string : 'development'
|
55
65
|
@development = (@env == 'development') ? true : false
|
@@ -97,6 +107,7 @@ module Isomorfeus
|
|
97
107
|
end
|
98
108
|
|
99
109
|
self.add_client_option(:client_init_class_names, [])
|
110
|
+
self.add_client_option(:client_init_after_store_class_names, [])
|
100
111
|
else
|
101
112
|
class << self
|
102
113
|
attr_accessor :server_side_rendering
|
@@ -1,5 +1,18 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module ReactViewHelper
|
3
|
+
def cached_mount_component(component_name, props = {}, asset = 'application_ssr.js')
|
4
|
+
key = "#{component_name}#{props}#{asset}"
|
5
|
+
if Isomorfeus.production? && component_cache.key?(key)
|
6
|
+
render_result = component_cache[key][:render_result]
|
7
|
+
@ssr_response_status = component_cache[key][:ssr_response_status]
|
8
|
+
@sst_styles = component_cache[key][:ssr_styles]
|
9
|
+
else
|
10
|
+
render_result = mount_component(component_name, props, asset)
|
11
|
+
component_cache[key] = { render_result: render_result, ssr_response_status: ssr_response_status, ssr_styles: ssr_styles }
|
12
|
+
end
|
13
|
+
render_result
|
14
|
+
end
|
15
|
+
|
3
16
|
def mount_component(component_name, props = {}, asset = 'application_ssr.js')
|
4
17
|
@ssr_response_status = nil
|
5
18
|
@ssr_styles = nil
|
@@ -51,7 +64,8 @@ module Isomorfeus
|
|
51
64
|
global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');
|
52
65
|
JAVASCRIPT
|
53
66
|
|
54
|
-
# if location_host and scheme are given and if Transport is loaded, connect and then render,
|
67
|
+
# if location_host and scheme are given and if Transport is loaded, connect and then render,
|
68
|
+
# otherwise do not render because only one pass is required
|
55
69
|
ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
|
56
70
|
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
57
71
|
api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
|
@@ -152,12 +166,16 @@ module Isomorfeus
|
|
152
166
|
|
153
167
|
# build result
|
154
168
|
render_result << " data-iso-hydrated='true'" if rendered_tree
|
155
|
-
render_result << " data-iso-nloc='#{props[:locale]}' data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
169
|
+
# render_result << " data-iso-nloc='#{props[:locale]}' data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
170
|
+
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
156
171
|
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
157
172
|
else
|
158
173
|
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
159
174
|
end
|
160
175
|
render_result << '</div>'
|
176
|
+
if Isomorfeus.server_side_rendering
|
177
|
+
render_result = "<script type='application/javascript'>\nServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}\n</script>\n" << render_result
|
178
|
+
end
|
161
179
|
render_result
|
162
180
|
end
|
163
181
|
|
@@ -168,5 +186,11 @@ module Isomorfeus
|
|
168
186
|
def ssr_styles
|
169
187
|
@ssr_styles || ''
|
170
188
|
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def component_cache
|
193
|
+
Thread.current[:component_cache] ||= {}
|
194
|
+
end
|
171
195
|
end
|
172
196
|
end
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -25,18 +25,21 @@ module Isomorfeus
|
|
25
25
|
props = `Opal.Hash.$new(JSON.parse(props_json))`
|
26
26
|
raw_hydrated = root_element.JS.getAttribute('data-iso-hydrated')
|
27
27
|
hydrated = (raw_hydrated && raw_hydrated == "true")
|
28
|
-
state_json = root_element.JS.getAttribute('data-iso-state')
|
29
|
-
if state_json
|
28
|
+
#state_json = root_element.JS.getAttribute('data-iso-state')
|
29
|
+
#if state_json
|
30
30
|
%x{
|
31
|
-
|
32
|
-
var
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
if (global.ServerSideRenderingStateJSON) {
|
32
|
+
var state = global.ServerSideRenderingStateJSON;
|
33
|
+
var keys = Object.keys(state);
|
34
|
+
for(var i=0; i < keys.length; i++) {
|
35
|
+
if (Object.keys(state[keys[i]]).length > 0) {
|
36
|
+
global.Opal.Isomorfeus.store.native.dispatch({ type: keys[i].toUpperCase(), set_state: state[keys[i]] });
|
37
|
+
}
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
39
|
-
end
|
41
|
+
#end
|
42
|
+
Isomorfeus.execute_init_after_store_classes
|
40
43
|
begin
|
41
44
|
result = Isomorfeus::TopLevel.mount_component(component, props, root_element, hydrated)
|
42
45
|
@tried_another_time = false
|
@@ -47,6 +47,7 @@ module LucidApp
|
|
47
47
|
this[ref] = Opal.global.React.createRef();
|
48
48
|
}
|
49
49
|
}
|
50
|
+
if (base.preload_block) { this.state.preloaded = this.__ruby_instance.$execute_preload_block(); }
|
50
51
|
this.listener = this.listener.bind(this);
|
51
52
|
this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
|
52
53
|
}
|
@@ -65,7 +66,7 @@ module LucidApp
|
|
65
66
|
oper.active_components.push(this);
|
66
67
|
oper.active_redux_components.push(this);
|
67
68
|
let block_result;
|
68
|
-
if (base.
|
69
|
+
if (base.while_loading_block && !this.state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
69
70
|
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
70
71
|
if (block_result && (block_result.constructor === String || block_result.constructor === Number)) { oper.render_buffer[oper.render_buffer.length - 1].push(block_result); }
|
71
72
|
oper.active_redux_components.pop();
|
@@ -37,6 +37,7 @@ module LucidComponent
|
|
37
37
|
this[ref] = Opal.global.React.createRef();
|
38
38
|
}
|
39
39
|
}
|
40
|
+
if (base.preload_block) { this.state.preloaded = this.__ruby_instance.$execute_preload_block(); }
|
40
41
|
}
|
41
42
|
static get displayName() {
|
42
43
|
return #{component_name};
|
@@ -52,16 +53,12 @@ module LucidComponent
|
|
52
53
|
oper.active_components.push(this);
|
53
54
|
oper.active_redux_components.push(this);
|
54
55
|
let block_result;
|
55
|
-
if (base.
|
56
|
+
if (base.while_loading_block && !this.state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
56
57
|
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
57
58
|
if (block_result && (block_result.constructor === String || block_result.constructor === Number)) { oper.render_buffer[oper.render_buffer.length - 1].push(block_result); }
|
58
59
|
oper.active_redux_components.pop();
|
59
60
|
oper.active_components.pop();
|
60
61
|
// console.log("lucid component popping", oper.render_buffer, oper.render_buffer.toString());
|
61
|
-
if (base.except_ssr) {
|
62
|
-
if (typeof block_result === "object" && block_result.danger) { return Opal.global.React.createElement('div', {'data-ssrhelper': this.__ruby_instance.$class().$to_s(), dangerouslySetInnerHTML: { __html: block_result.html}});}
|
63
|
-
else { return Opal.global.React.createElement('div', {'data-ssrhelper': this.__ruby_instance.$class().$to_s()}, oper.render_buffer.pop()); }
|
64
|
-
}
|
65
62
|
return oper.render_buffer.pop();
|
66
63
|
}
|
67
64
|
data_access() {
|
@@ -5,34 +5,27 @@ module LucidComponent
|
|
5
5
|
def preload(&block)
|
6
6
|
`base.preload_block = block`
|
7
7
|
component_did_mount do
|
8
|
-
|
9
|
-
self.state.preloaded = true
|
10
|
-
end
|
8
|
+
@_preload_promise.then { self.state.preloaded = true } unless self.state.preloaded
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
12
|
def while_loading(option = nil, &block)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
proc do
|
22
|
-
%x{
|
23
|
-
let query = "[data-ssrhelper='" + #{self.class.to_s} + "']";
|
24
|
-
let el = document.querySelector(query);
|
25
|
-
if (el) { return { danger: true, html: el.innerHTML }; }
|
26
|
-
else { return #{instance_exec(&given_block)};
|
27
|
-
}
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
13
|
+
wl_block = proc do
|
14
|
+
if @_preload_promise.resolved?
|
15
|
+
instance_exec(&`base.render_block`)
|
16
|
+
else
|
17
|
+
instance_exec(&block)
|
18
|
+
end
|
31
19
|
end
|
32
|
-
`base.while_loading_block =
|
20
|
+
`base.while_loading_block = wl_block`
|
33
21
|
end
|
34
22
|
end
|
35
23
|
|
24
|
+
def execute_preload_block
|
25
|
+
@_preload_promise = instance_exec(&self.class.JS[:preload_block])
|
26
|
+
@_preload_promise.resolved?
|
27
|
+
end
|
28
|
+
|
36
29
|
def preloaded?
|
37
30
|
!!state.preloaded
|
38
31
|
end
|
@@ -7,11 +7,11 @@ module LucidMaterial
|
|
7
7
|
base.store_updates = true;
|
8
8
|
base.equality_checker = null;
|
9
9
|
base.instance_init = function(initial) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
let ruby_state = { instance: #{base.new(`{}`)} };
|
11
|
+
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
12
|
+
ruby_state.instance.data_access = function() { return this.props.store; }
|
13
|
+
ruby_state.instance.data_access.bind(ruby_state.instance);
|
14
|
+
return ruby_state;
|
15
15
|
}
|
16
16
|
base.instance_reducer = function(state, action) { return state; }
|
17
17
|
base.react_component = Opal.global.React.memo(function(props) {
|
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.4
|
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-12-
|
11
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.0.
|
75
|
+
version: 0.0.4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.0.
|
82
|
+
version: 0.0.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: opal-webpack-loader
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|