svelte-on-rails 4.1.0 → 4.1.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/README.md +10 -14
- data/lib/svelte_on_rails/lib/view_helper_support.rb +10 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1113ad80ad88261fdf387b8d033006e10cedcbb0bd4e941a5a6fd8d7c338e2e
|
4
|
+
data.tar.gz: de7a37961949e4ff3f99de2da8818e159b3afc552dd530f1373607101c2a50db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e173b7d27296c0a51f7ea6d35632fab227e34964353087354fcd10634efc004959140da5724094b486dbb0a009e10af7a65e809d152b5621ac82911d5efc5198
|
7
|
+
data.tar.gz: 0d8f6bc08236e2752c81c7f1353f36c41c67ea9e4937410658ead038351b1ff0a323992af634b8b084e36d017facb6775cc41b0efa3cabd2989f5cd47620d81d
|
data/README.md
CHANGED
@@ -300,6 +300,12 @@ the Svelte component is not visible for the first moment after rendering.
|
|
300
300
|
Server-side rendering is unnecessary here. You can pass 'ssr: false' to the view helper.
|
301
301
|
This relieves the server and reduces loading time.
|
302
302
|
|
303
|
+
**Tip: Testing**
|
304
|
+
|
305
|
+
Consider setting `ssr: false` for testing only for performance reasons.
|
306
|
+
Yo can override this on a attribute on the view-helper for specific components.
|
307
|
+
But, in normal cases it should not be neccessary testing ssr explicitly.
|
308
|
+
|
303
309
|
## Caching
|
304
310
|
|
305
311
|
Caching only is relevant for `ssr`
|
@@ -314,26 +320,16 @@ This caches on a key like `svelte-on-rails:development:SvelteOnRailsHelloWorld.s
|
|
314
320
|
- `cache_key` if given as argument to the view-helper
|
315
321
|
- can be a array of active-record objects or strings or a single element instead of a array
|
316
322
|
- hash of the last modification timestamp of the component (only when `watch_changes` is set to true)
|
317
|
-
- hash of the given
|
318
|
-
|
319
|
-
**Caching strategy (!)**
|
320
|
-
|
321
|
-
Everytime the properties are changing, which are the last two elements of the hash key, which means all after the last colon,
|
322
|
-
Previous hash keys are cleared by, for example: `svelte-on-rails:development:SvelteOnRailsHelloWorld.svelte-1xq5tnu-User1:*`
|
323
|
-
|
324
|
-
That means: Please be aware to set your `cache_key` precisely for not invalidating cache keys that should not be cleared.
|
325
|
-
|
326
|
-
On the other hand, please be aware that generating lots of record dependent cache keys will consume your memory, dependent on your
|
327
|
-
redis configuration.
|
323
|
+
- hash of the given attributes
|
328
324
|
|
329
|
-
**
|
325
|
+
**Configuration**
|
330
326
|
|
331
327
|
Like usually you can configure your cache store on your environment by something like:
|
332
328
|
|
333
329
|
```ruby
|
334
330
|
config.cache_store = :redis_cache_store, { url: 'redis://localhost:6379/2',
|
335
331
|
expires_in: 90.minutes,
|
336
|
-
namespace: '
|
332
|
+
namespace: 'my-example-app' }
|
337
333
|
```
|
338
334
|
|
339
335
|
And you can override this by
|
@@ -345,7 +341,7 @@ redis_cache_store:
|
|
345
341
|
|
346
342
|
on the svelte-on-rails config file.
|
347
343
|
|
348
|
-
**
|
344
|
+
**Check if it works**
|
349
345
|
|
350
346
|
Pass `debug: true` to the helper and you will see on the logs how your configuration works.
|
351
347
|
|
@@ -5,14 +5,14 @@ module SvelteOnRails
|
|
5
5
|
class ViewHelperSupport
|
6
6
|
attr_reader :filename, :helper_options, :html_options, :request, :conf
|
7
7
|
|
8
|
-
def initialize(file,
|
8
|
+
def initialize(file, args, request, caching = false)
|
9
9
|
|
10
10
|
@start_time = Time.now
|
11
11
|
@filename = (file.match(/\.svelte$/) ? file[0..-8] : file)
|
12
|
+
@args_checksum = Zlib.crc32(args.to_json).to_s(36)
|
12
13
|
@conf = SvelteOnRails::Configuration.instance
|
13
|
-
@
|
14
|
-
|
15
|
-
props,
|
14
|
+
@helper_options, @html_options, @svelte_props = split_props(
|
15
|
+
args,
|
16
16
|
%i[class id style],
|
17
17
|
%i[ssr hydrate debug cache_key expires_in]
|
18
18
|
)
|
@@ -36,8 +36,6 @@ module SvelteOnRails
|
|
36
36
|
return
|
37
37
|
end
|
38
38
|
|
39
|
-
return unless ssr?
|
40
|
-
|
41
39
|
generate_cache_key
|
42
40
|
|
43
41
|
end
|
@@ -98,7 +96,7 @@ module SvelteOnRails
|
|
98
96
|
|
99
97
|
def render_ssr
|
100
98
|
renderer = SvelteOnRails::Renderer.new(filename)
|
101
|
-
renderer.render(@
|
99
|
+
renderer.render(@svelte_props)
|
102
100
|
end
|
103
101
|
|
104
102
|
def custom_cache_key
|
@@ -163,14 +161,14 @@ module SvelteOnRails
|
|
163
161
|
|
164
162
|
last_part = [
|
165
163
|
(@conf.watch_changes? ? Zlib.crc32(mtime).to_s(36) : nil),
|
166
|
-
|
164
|
+
@args_checksum
|
167
165
|
].compact.join('-')
|
168
166
|
|
169
167
|
@cache_key = [@cache_key_primary, last_part].join(':')
|
170
168
|
|
171
169
|
end
|
172
170
|
|
173
|
-
def split_props(
|
171
|
+
def split_props(args, html_options, helper_options)
|
174
172
|
prp = {}
|
175
173
|
hlp_opts = {}
|
176
174
|
ht_opts = {
|
@@ -180,7 +178,7 @@ module SvelteOnRails
|
|
180
178
|
}
|
181
179
|
}
|
182
180
|
|
183
|
-
|
181
|
+
args.each do |k, v|
|
184
182
|
_k = k.to_sym
|
185
183
|
if helper_options.include?(_k)
|
186
184
|
hlp_opts[_k] = v
|
@@ -192,11 +190,10 @@ module SvelteOnRails
|
|
192
190
|
end
|
193
191
|
|
194
192
|
ht_opts[:class] = "#{ht_opts[:class]} svelte-component".strip
|
195
|
-
|
196
|
-
ht_opts[:data][:props] = prp_js
|
193
|
+
ht_opts[:data][:props] = prp.to_json
|
197
194
|
ht_opts[:data][:svelte_status] = 'do-not-hydrate-me' if hlp_opts[:hydrate] == false
|
198
195
|
|
199
|
-
[hlp_opts, ht_opts, prp
|
196
|
+
[hlp_opts, ht_opts, prp]
|
200
197
|
end
|
201
198
|
|
202
199
|
end
|