live_component 0.2.0 → 0.3.0
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/CHANGELOG.md +3 -0
- data/app/channels/live_component_channel.rb +2 -2
- data/app/helpers/live_component/application_helper.rb +4 -1
- data/lib/live_component/action.rb +2 -2
- data/lib/live_component/middleware.rb +2 -2
- data/lib/live_component/payload.rb +6 -4
- data/lib/live_component/target.rb +1 -5
- data/lib/live_component/utils.rb +4 -0
- data/lib/live_component/version.rb +1 -1
- 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: cb43e1e1745df75bcdd80bbec779b79d43bc061fe2658406fac739933cb63cbf
|
|
4
|
+
data.tar.gz: '0832ba6384ce51daa2abe3e785c4f361b698517b5532fea478332e23c706ff4e'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50a61a4d6d5c56aeb50010a8adb4ece3fa4507ebbf9e4a5770414098de65fe6461b8dfb8c2fb7a4f3aad7ebd6ab4fa521d8cee218f62e09fa623fe192bbcf6b1
|
|
7
|
+
data.tar.gz: d6deaa38293b3c98ae7eaa8a7925f3d18cc6c0b59479300cd1376b834ad3159f7863eb9c7278ddc1634a67351c2add2053e41d1452183d293aa0cccd05480b61
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# 0.3.0
|
|
2
|
+
* Only use `CompressionStream` if it's available, i.e. we're running in a modern-ish browser.
|
|
3
|
+
|
|
1
4
|
# 0.2.0
|
|
2
5
|
* Rename `ModelSerializer`'s `load` option to `reload`, since that's what it does.
|
|
3
6
|
* Rename `ModelSerializer#add_serializer` to `#register` for consistency with other parts of the library.
|
|
@@ -7,13 +7,13 @@ class LiveComponentChannel < ActionCable::Channel::Base
|
|
|
7
7
|
|
|
8
8
|
def receive(data)
|
|
9
9
|
request_id = data["request_id"]
|
|
10
|
-
payload = LiveComponent::Payload.decode(data["payload"])
|
|
10
|
+
payload, compressed = LiveComponent::Payload.decode(data["payload"])
|
|
11
11
|
|
|
12
12
|
result = LiveComponent::RenderController.renderer.render(
|
|
13
13
|
:show, assigns: { state: payload["state"], reflexes: payload["reflexes"] }, layout: false
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
result = LiveComponent::Payload.encode(result)
|
|
16
|
+
result = LiveComponent::Payload.encode(result, compress: compressed)
|
|
17
17
|
|
|
18
18
|
ActionCable.server.broadcast(
|
|
19
19
|
"live_component",
|
|
@@ -28,7 +28,10 @@ module LiveComponent
|
|
|
28
28
|
|
|
29
29
|
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
|
30
30
|
if block_given?
|
|
31
|
-
|
|
31
|
+
if content_or_options_with_block.is_a?(Hash)
|
|
32
|
+
options = content_or_options_with_block
|
|
33
|
+
content_or_options_with_block = nil
|
|
34
|
+
end
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
options ||= {}
|
|
@@ -21,9 +21,9 @@ module LiveComponent
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def to_attributes
|
|
24
|
-
{
|
|
24
|
+
{}.tap do |attrs|
|
|
25
25
|
if @method_name
|
|
26
|
-
attrs[:data
|
|
26
|
+
attrs[:"data-action"] = "#{@event_name}->#{@controller_name}##{@method_name}"
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -12,13 +12,13 @@ module LiveComponent
|
|
|
12
12
|
if env["PATH_INFO"] == "/live_component/render"
|
|
13
13
|
raw_data = env["rack.input"].read
|
|
14
14
|
data = JSON.parse(raw_data)
|
|
15
|
-
payload = LiveComponent::Payload.decode(data["payload"])
|
|
15
|
+
payload, compressed = LiveComponent::Payload.decode(data["payload"])
|
|
16
16
|
|
|
17
17
|
result = LiveComponent::RenderController.renderer.render(
|
|
18
18
|
:show, assigns: { state: payload["state"], reflexes: payload["reflexes"] }, layout: false
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
result = LiveComponent::Payload.encode(result)
|
|
21
|
+
result = LiveComponent::Payload.encode(result, compress: compressed)
|
|
22
22
|
|
|
23
23
|
return [200, { "Content-Type" => "text/html" }, [result]]
|
|
24
24
|
end
|
|
@@ -11,12 +11,14 @@ module LiveComponent
|
|
|
11
11
|
class << self
|
|
12
12
|
def decode(data)
|
|
13
13
|
data = Base64.decode64(data)
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
compressed = gzipped?(data)
|
|
15
|
+
data = Zlib.gunzip(data) if compressed
|
|
16
|
+
[JSON.parse(data), compressed]
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def encode(data)
|
|
19
|
-
|
|
19
|
+
def encode(data, compress: true)
|
|
20
|
+
data = Zlib.gzip(data) if compress
|
|
21
|
+
Base64.encode64(data)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
private
|
data/lib/live_component/utils.rb
CHANGED
|
@@ -50,6 +50,10 @@ module LiveComponent
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def translate_all_attrs(kwargs)
|
|
53
|
+
kwargs = kwargs.reject do |_, v|
|
|
54
|
+
v.is_a?(String) && v.start_with?("fn:")
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
# TODO: allow folks to add their own attr classes?
|
|
54
58
|
[Action, Target].inject(kwargs) do |memo, attr_klass|
|
|
55
59
|
if kwargs.include?(attr_klass.attr_name)
|