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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43687d7606d4a9a709a4b9868c486c2c211876b9281f0c3febf3826ab9566a48
4
- data.tar.gz: 0b11c309f69b00fc70d9b660196ab5813a9f3d3972129a8bc330738a7dde5c82
3
+ metadata.gz: cb43e1e1745df75bcdd80bbec779b79d43bc061fe2658406fac739933cb63cbf
4
+ data.tar.gz: '0832ba6384ce51daa2abe3e785c4f361b698517b5532fea478332e23c706ff4e'
5
5
  SHA512:
6
- metadata.gz: 9a8e42c4dbf902dbf5d22e6a23a945abb08314ea23e1aa859f5d41b114a6331af63c587c859e38599ecbd856940146f4582b7587000123d4030f9f3ffc29b633
7
- data.tar.gz: 443674a0e1b54f76e2f43cce047a54b84ec18a8ff513978febe806b007dce45286042a7cc2286826e5873fd2915de61b88da072e0cf8662d884b665118085de7
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
- options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
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
- { data: {} }.tap do |attrs|
24
+ {}.tap do |attrs|
25
25
  if @method_name
26
- attrs[:data][:action] = "#{@event_name}->#{@controller_name}##{@method_name}"
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
- data = Zlib.gunzip(data) if gzipped?(data)
15
- JSON.parse(data)
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
- Base64.encode64(Zlib.gzip(data))
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
@@ -8,11 +8,7 @@ module LiveComponent
8
8
  end
9
9
 
10
10
  def to_attributes
11
- {
12
- data: {
13
- "#{@controller_name}-target": @target_name
14
- }
15
- }
11
+ { "data-#{@controller_name}-target": @target_name.to_s }
16
12
  end
17
13
 
18
14
  def self.attr_name
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LiveComponent
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: live_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro