Module: LiveCable::Component::Broadcasting
- Extended by:
- ActiveSupport::Concern
- Included in:
- LiveCable::Component
- Defined in:
- lib/live_cable/component/broadcasting.rb
Instance Method Summary collapse
- #broadcast(data) ⇒ Object
-
#broadcast_ack ⇒ Object
Sent when a received message didn't change any reactive variables, so the client can clear its loading state without a re-render.
- #broadcast_destroy ⇒ Object
- #broadcast_render ⇒ Object
- #broadcast_subscribe ⇒ Object
Instance Method Details
#broadcast(data) ⇒ Object
8 9 10 |
# File 'lib/live_cable/component/broadcasting.rb', line 8 def broadcast(data) ActionCable.server.broadcast(channel_name, data) end |
#broadcast_ack ⇒ Object
Sent when a received message didn't change any reactive variables, so the client can clear its loading state without a re-render.
18 19 20 |
# File 'lib/live_cable/component/broadcasting.rb', line 18 def broadcast_ack broadcast({ _ack: true }) end |
#broadcast_destroy ⇒ Object
22 23 24 25 |
# File 'lib/live_cable/component/broadcasting.rb', line 22 def broadcast_destroy broadcast({ _status: 'destroy' }) @subscribed = false end |
#broadcast_render ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/live_cable/component/broadcasting.rb', line 27 def broadcast_render run_callbacks :render do data = { _refresh: render.as_json } # Events ride along with the render so the client can fire them # after the DOM has been morphed events = flush_events data[:_events] = events if events.any? broadcast(data) end end |
#broadcast_subscribe ⇒ Object
12 13 14 |
# File 'lib/live_cable/component/broadcasting.rb', line 12 def broadcast_subscribe broadcast({ _status: 'subscribed', id: live_id }) end |