live 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb8e5793466102d92b796d1e86a24c1ff6406eb888b772c65a22c1857c49ad5e
4
- data.tar.gz: b19804c4d65fa9798615bb681c5062602e2a0406b8a663ac1e8c4ef8a7f2b3c4
3
+ metadata.gz: 01e0a2e5881cd9cb589f93184b159a022a884a3b6549d6da54764ebe05bd8b81
4
+ data.tar.gz: 3cc1bd067307955f663cd9318bf60ec80dce9a4759df0935d3b00176c0183c85
5
5
  SHA512:
6
- metadata.gz: 5a9c0e7beec4ba0f3102067b1df4da1329fcd35a90e2eb0de38db4ffa565dea7e56d52c6f4c922efd31aac0ee18d8427c40491f552ff3b5fafdec8d887d38898
7
- data.tar.gz: 75f1b08b01c5b1f280ff93290082bc1da873ff1e259e0a76f0b7a996516fcde81cbe1ceb0824e6f817318d100ec86af05714fbcdc5550526e8572ac6eed71e59
6
+ metadata.gz: b74fd0f4365c5eb0fcf8ed1b8064ad5efd39ebcd56a12b4cb9e144a6dce0a503eb14f054fb16332b20abe905c364b36486b594ab9f4992fb645d41fff860be21
7
+ data.tar.gz: 80a79b3466c52e0cc0989416c547c06e39d9059a910489a16c713ab046a83480b10c645e33420fc31fa262894c02d9bcef01a7c9e3fe17e86f571524bc1eb519
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/live/element.rb CHANGED
@@ -30,18 +30,18 @@ module Live
30
30
  attr :data
31
31
 
32
32
  # Generate a JavaScript string which forwards the specified event to the server.
33
- # @parameter details [Hash] The details associated with the forwarded event.
34
- def forward_event(details = nil)
35
- if details
36
- "live.forwardEvent(#{JSON.dump(@id)}, event, #{JSON.dump(details)})"
33
+ # @parameter detail [Hash] The detail associated with the forwarded event.
34
+ def forward_event(detail = nil)
35
+ if detail
36
+ "live.forwardEvent(#{JSON.dump(@id)}, event, #{JSON.dump(detail)})"
37
37
  else
38
38
  "live.forwardEvent(#{JSON.dump(@id)}, event)"
39
39
  end
40
40
  end
41
41
 
42
- def forward_form_event(details = nil)
43
- if details
44
- "live.forwardFormEvent(#{JSON.dump(@id)}, event, #{JSON.dump(details)})"
42
+ def forward_form_event(detail = nil)
43
+ if detail
44
+ "live.forwardFormEvent(#{JSON.dump(@id)}, event, #{JSON.dump(detail)})"
45
45
  else
46
46
  "live.forwardFormEvent(#{JSON.dump(@id)}, event)"
47
47
  end
data/lib/live/page.rb CHANGED
@@ -43,14 +43,13 @@ module Live
43
43
  # Handle an event from the client. If the element could not be found, it is silently ignored.
44
44
  # @parameter id [String] The unique identifier of the element which forwarded the event.
45
45
  # @parameter event [String] The type of the event.
46
- # @parameter details [Hash] The associated details if any.
47
46
  # @returns [Object] The result of the element handler, if the element was found.
48
47
  # @returns [Nil] If the element could not be found.
49
48
  def handle(id, event)
50
49
  if element = @elements[id]
51
50
  return element.handle(event)
52
51
  else
53
- Console.warn(self, "Could not handle event:", event, details)
52
+ Console.warn(self, "Could not handle event:", id:, event:)
54
53
  end
55
54
 
56
55
  return nil
@@ -64,14 +63,26 @@ module Live
64
63
 
65
64
  # Process a single incoming message from the network.
66
65
  def process_message(message)
67
- if id = message[:bind] and data = message[:data]
68
- if element = self.resolve(id, data)
66
+ case message[0]
67
+ when 'bind'
68
+ # Bind a client-side element to a server-side element.
69
+ if element = self.resolve(message[1], message[2])
69
70
  self.bind(element)
70
71
  else
71
72
  Console.warn(self, "Could not resolve element:", message)
73
+ # @updates.enqueue(['error', message[1], "Could not resolve element!"])
72
74
  end
73
- elsif id = message[:id]
74
- self.handle(id, message[:event])
75
+ when 'unbind'
76
+ # Unbind a client-side element from a server-side element.
77
+ if element = @elements.delete(message[1])
78
+ element.close
79
+ else
80
+ Console.warn(self, "Could not unbind element:", message)
81
+ @updates.enqueue(['error', message[1], "Could not unbind element!"])
82
+ end
83
+ when 'event'
84
+ # Handle an event from the client.
85
+ self.handle(message[1], message[2])
75
86
  else
76
87
  Console.warn(self, "Unhandled message:", message)
77
88
  end
data/lib/live/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  module Live
7
- VERSION = "0.7.0"
7
+ VERSION = "0.8.0"
8
8
  end
data/lib/live.rb CHANGED
@@ -7,4 +7,4 @@ require_relative "live/version"
7
7
 
8
8
  require_relative 'live/page'
9
9
  require_relative 'live/view'
10
-
10
+ require_relative 'live/resolver'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2024-05-04 00:00:00.000000000 Z
41
+ date: 2024-05-05 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: async-websocket
metadata.gz.sig CHANGED
Binary file