isomorfeus-react 16.13.0 → 16.13.1
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.rb +4 -2
- data/lib/isomorfeus/react_config.rb +26 -1
- data/lib/isomorfeus/react_view_helper.rb +11 -15
- data/lib/isomorfeus/thread_local_component_cache.rb +15 -0
- data/lib/react/version.rb +1 -1
- metadata +5 -5
- data/lib/isomorfeus/thread_local_cache.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c28956343a2d33bfd6e86a406a1479b403a609f482dc283df7e60dfee2b52fb
|
4
|
+
data.tar.gz: 6909f97fa27587d1635256763cf19d7fede19704f2027876b486043c48d291b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad4419cf10814eaf6c2c85dd36450f83ff321a38f47672342faa6a6b136110fcea7710aaae32fa10ea09c4794e226346bbde0a18a7d93ae9e59b2191fdeef2e6
|
7
|
+
data.tar.gz: 9ecdaa132dd659a414a9a6f1826b847476686ee3432c1b7827bdfb7a03755f9e9e67c1607a54675ebcf6f4b094c5508d8ad5f219c37a72b8a9567a93566892f6
|
data/lib/isomorfeus-react.rb
CHANGED
@@ -100,10 +100,12 @@ else
|
|
100
100
|
Isomorfeus.server_side_rendering = true
|
101
101
|
|
102
102
|
# cache
|
103
|
-
require 'isomorfeus/
|
103
|
+
require 'isomorfeus/thread_local_component_cache'
|
104
104
|
require 'isomorfeus/react_view_helper'
|
105
105
|
|
106
|
-
Isomorfeus.
|
106
|
+
Isomorfeus.component_cache do
|
107
|
+
Isomorfeus::ThreadLocalComponentCache.new
|
108
|
+
end
|
107
109
|
|
108
110
|
Opal.append_path(__dir__.untaint)
|
109
111
|
|
@@ -109,13 +109,17 @@ module Isomorfeus
|
|
109
109
|
self.add_client_option(:client_init_after_store_class_names, [])
|
110
110
|
else
|
111
111
|
class << self
|
112
|
-
|
112
|
+
attr_reader :component_cache
|
113
113
|
attr_accessor :server_side_rendering
|
114
114
|
attr_accessor :ssr_hot_asset_url
|
115
115
|
attr_reader :env
|
116
116
|
attr_accessor :zeitwerk
|
117
117
|
attr_accessor :zeitwerk_lock
|
118
118
|
|
119
|
+
def component_cache(&block)
|
120
|
+
@component_cache = block
|
121
|
+
end
|
122
|
+
|
119
123
|
def configuration(&block)
|
120
124
|
block.call(self)
|
121
125
|
end
|
@@ -146,6 +150,12 @@ module Isomorfeus
|
|
146
150
|
def version
|
147
151
|
Isomorfeus::VERSION
|
148
152
|
end
|
153
|
+
|
154
|
+
def load_configuration
|
155
|
+
Dir.glob("config/*.rf").sort.each do |file|
|
156
|
+
require_relative file
|
157
|
+
end
|
158
|
+
end
|
149
159
|
end
|
150
160
|
end
|
151
161
|
|
@@ -155,9 +165,24 @@ module Isomorfeus
|
|
155
165
|
execution_environment = if on_browser? then 'on Browser'
|
156
166
|
elsif on_ssr? then 'in Server Side Rendering'
|
157
167
|
elsif on_server? then 'on Server'
|
168
|
+
elsif on_mobile? then 'on Mobile'
|
169
|
+
elsif on_database? then 'on Database'
|
170
|
+
else
|
171
|
+
'on Client'
|
158
172
|
end
|
159
173
|
error = error_class.new("Isomorfeus in #{env} #{execution_environment}:\n#{message}")
|
160
174
|
error.set_backtrace(stack) if stack
|
175
|
+
|
176
|
+
if Isomorfeus.development?
|
177
|
+
if RUBY_ENGINE == 'opal'
|
178
|
+
ecn = error_class ? error_class.name : ''
|
179
|
+
m = message ? message : ''
|
180
|
+
s = stack ? stack : ''
|
181
|
+
`console.error(ecn, m, s)`
|
182
|
+
else
|
183
|
+
STDERR.puts "#{ecn}: #{m}\n #{s}"
|
184
|
+
end
|
185
|
+
end
|
161
186
|
raise error
|
162
187
|
end
|
163
188
|
end
|
@@ -1,26 +1,22 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module ReactViewHelper
|
3
|
-
def cached_mount_component(component_name, props = {}, asset = '
|
3
|
+
def cached_mount_component(component_name, props = {}, asset = 'web_ssr.js', static = false)
|
4
4
|
key = "#{component_name}#{props}#{asset}"
|
5
|
-
if Isomorfeus.production?
|
6
|
-
render_result = component_cache
|
7
|
-
|
8
|
-
@sst_styles = component_cache[key][:ssr_styles]
|
9
|
-
else
|
10
|
-
render_result = mount_component(component_name, props, asset, static)
|
11
|
-
status = ssr_response_status
|
12
|
-
if status >= 200 && status < 300
|
13
|
-
component_cache[key] = { render_result: render_result, ssr_response_status: status, ssr_styles: ssr_styles }
|
14
|
-
end
|
5
|
+
if Isomorfeus.production?
|
6
|
+
render_result, @ssr_response_status, @ssr_styles = component_cache.fetch(key)
|
7
|
+
return render_result if render_result
|
15
8
|
end
|
9
|
+
render_result = mount_component(component_name, props, asset, static)
|
10
|
+
status = ssr_response_status
|
11
|
+
component_cache.set(key, render_result, status, ssr_styles) if status >= 200 && status < 300
|
16
12
|
render_result
|
17
13
|
end
|
18
14
|
|
19
|
-
def cached_mount_static_component(component_name, props = {}, asset = '
|
15
|
+
def cached_mount_static_component(component_name, props = {}, asset = 'web_ssr.js')
|
20
16
|
cached_mount_component(component_name, props, asset, true)
|
21
17
|
end
|
22
18
|
|
23
|
-
def mount_component(component_name, props = {}, asset = '
|
19
|
+
def mount_component(component_name, props = {}, asset = 'web_ssr.js', static = false)
|
24
20
|
@ssr_response_status = nil
|
25
21
|
@ssr_styles = nil
|
26
22
|
thread_id_asset = "#{Thread.current.object_id}#{asset}"
|
@@ -214,7 +210,7 @@ module Isomorfeus
|
|
214
210
|
render_result
|
215
211
|
end
|
216
212
|
|
217
|
-
def mount_static_component(component_name, props = {}, asset = '
|
213
|
+
def mount_static_component(component_name, props = {}, asset = 'web_ssr.js')
|
218
214
|
mount_component(component_name, props, asset, true)
|
219
215
|
end
|
220
216
|
|
@@ -229,7 +225,7 @@ module Isomorfeus
|
|
229
225
|
private
|
230
226
|
|
231
227
|
def component_cache
|
232
|
-
@_component_cache ||= Isomorfeus.
|
228
|
+
@_component_cache ||= Isomorfeus.component_cache.call
|
233
229
|
end
|
234
230
|
end
|
235
231
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
class ThreadLocalComponentCache
|
3
|
+
def initialize
|
4
|
+
Thread.current[:local_cache] = {} unless Thread.current.key?(:local_cache)
|
5
|
+
end
|
6
|
+
|
7
|
+
def fetch(key)
|
8
|
+
Thread.current[:local_cache][key]
|
9
|
+
end
|
10
|
+
|
11
|
+
def store(key, rendered_tree, response_status, styles)
|
12
|
+
Thread.current[:local_cache][key] = [rendered_tree, response_status, styles]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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.13.
|
4
|
+
version: 16.13.1
|
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-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.9.
|
89
|
+
version: 0.9.11
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.9.
|
96
|
+
version: 0.9.11
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: isomorfeus-redux
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,7 +200,7 @@ files:
|
|
200
200
|
- lib/isomorfeus/props/validator.rb
|
201
201
|
- lib/isomorfeus/react_config.rb
|
202
202
|
- lib/isomorfeus/react_view_helper.rb
|
203
|
-
- lib/isomorfeus/
|
203
|
+
- lib/isomorfeus/thread_local_component_cache.rb
|
204
204
|
- lib/isomorfeus/top_level.rb
|
205
205
|
- lib/isomorfeus/top_level_ssr.rb
|
206
206
|
- lib/isomorfeus/vivify_module.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
class ThreadLocalCache
|
3
|
-
def initialize
|
4
|
-
Thread.current[:local_cache] = {} unless Thread.current.key?(:local_cache)
|
5
|
-
end
|
6
|
-
|
7
|
-
def [](key)
|
8
|
-
Thread.current[:local_cache][key]
|
9
|
-
end
|
10
|
-
alias fetch []
|
11
|
-
|
12
|
-
def []=(key, value)
|
13
|
-
Thread.current[:local_cache][key] = value
|
14
|
-
end
|
15
|
-
alias store []=
|
16
|
-
|
17
|
-
def key?(key)
|
18
|
-
Thread.current[:local_cache].key?(key)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|