Skip to content

Commit ebd1ca2

Browse files
committed
Fix rpc + logging.
1 parent d07030c commit ebd1ca2

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

lib/live/element.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def handle(event)
5757
# Enqueue a remote procedure call to the currently bound page.
5858
# @parameter method [Symbol] The name of the remote functio to invoke.
5959
# @parameter arguments [Array]
60-
def rpc(method, arguments)
60+
def rpc(*arguments)
6161
# This update might not be sent right away. Therefore, mutable arguments may be serialized to JSON at a later time (or never). This could be a race condition:
62-
@page.updates.enqueue([method, arguments])
62+
@page.updates.enqueue(arguments)
6363
end
6464
end
6565
end

lib/live/page.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def handle(id, event)
5050
if element = @elements[id]
5151
return element.handle(event)
5252
else
53-
Console.logger.warn(self, "Could not handle event:", event, details)
53+
Console.warn(self, "Could not handle event:", event, details)
5454
end
5555

5656
return nil
@@ -68,12 +68,12 @@ def process_message(message)
6868
if element = self.resolve(id, data)
6969
self.bind(element)
7070
else
71-
Console.logger.warn(self, "Could not resolve element:", message)
71+
Console.warn(self, "Could not resolve element:", message)
7272
end
7373
elsif id = message[:id]
7474
self.handle(id, message[:event])
7575
else
76-
Console.logger.warn(self, "Unhandled message:", message)
76+
Console.warn(self, "Unhandled message:", message)
7777
end
7878
end
7979

@@ -82,20 +82,20 @@ def process_message(message)
8282
def run(connection)
8383
queue_task = Async do
8484
while update = @updates.dequeue
85-
Console.logger.debug(self, "Sending update:", update)
85+
Console.debug(self, "Sending update:", update)
8686

8787
connection.write(::Protocol::WebSocket::JSONMessage.generate(update))
8888
connection.flush if @updates.empty?
8989
end
9090
end
9191

9292
while message = connection.read
93-
Console.logger.debug(self, "Reading message:", message)
93+
Console.debug(self, "Reading message:", message)
9494

9595
if json_message = ::Protocol::WebSocket::JSONMessage.wrap(message)
9696
process_message(json_message.parse)
9797
else
98-
Console.logger.warn(self, "Unhandled message:", message)
98+
Console.warn(self, "Unhandled message:", message)
9999
end
100100
end
101101
ensure

lib/live/view.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,38 @@ module Live
1111
class View < Element
1212
# Update the content of the client-side element by rendering this view.
1313
def update!(**options)
14-
rpc(:update, [@id, self.to_html, options])
14+
rpc(:update, @id, self.to_html, options)
1515
end
1616

1717
# Replace the content of the client-side element by rendering this view.
1818
# @parameter selector [String] The CSS selector to replace.
1919
# @parameter node [String] The HTML to replace.
2020
def replace(selector, node, **options)
21-
rpc(:replace, [selector, node.to_s, options])
21+
rpc(:replace, selector, node.to_s, options)
2222
end
2323

2424
# Prepend to the content of the client-side element by appending the specified element.
2525
# @parameter selector [String] The CSS selector to prepend to.
2626
# @parameter node [String] The HTML to prepend.
2727
def prepend(selector, node, **options)
28-
rpc(:prepend, [selector, node.to_s, options])
28+
rpc(:prepend, selector, node.to_s, options)
2929
end
3030

3131
# Append to the content of the client-side element by appending the specified element.
3232
# @parameter selector [String] The CSS selector to append to.
3333
# @parameter node [String] The HTML to prepend.
3434
def append(selector, node, **options)
35-
rpc(:append, [selector, node.to_s, options])
35+
rpc(:append, selector, node.to_s, options)
3636
end
3737

3838
# Remove the specified element from the client-side element.
3939
# @parameter selector [String] The CSS selector to remove.
4040
def remove(selector, **options)
41-
rpc(:remove, [selector, options])
41+
rpc(:remove, selector, options)
4242
end
4343

4444
def dispatch_event(selector, type, **options)
45-
rpc(:dispatch_event, [selector, event, options])
45+
rpc(:dispatch_event, selector, event, options)
4646
end
4747

4848
# Render the element.

test/live/website.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.name
1414
"TestTag"
1515
end
1616

17-
def bind(page)
17+
def bind(...)
1818
super
1919

2020
@clock ||= Async do
@@ -55,7 +55,6 @@ def content_type(path)
5555

5656
def app
5757
::Protocol::HTTP::Middleware.for do |request|
58-
Console.info(self, "Handling request", request:)
5958
local_path = File.join(root, request.path)
6059

6160
if File.file?(local_path)

0 commit comments

Comments
 (0)