Class: LiveComponentChannel

Inherits:
ActionCable::Channel::Base
  • Object
show all
Defined in:
app/channels/live_component_channel.rb

Instance Method Summary collapse

Instance Method Details

#receive(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/channels/live_component_channel.rb', line 8

def receive(data)
  request_id = data["request_id"]
  payload, compressed = LiveComponent::Payload.decode(data["payload"])

  result = LiveComponent::RenderController.renderer.render(
    :show, assigns: { state: payload["state"], reflexes: payload["reflexes"] }, layout: false
  )

  result = LiveComponent::Payload.encode(result, compress: compressed)

  ActionCable.server.broadcast(
    "live_component",
    { payload: result, request_id: request_id }
  )
end

#subscribedObject



4
5
6
# File 'app/channels/live_component_channel.rb', line 4

def subscribed
  stream_from "live_component"
end