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
Nil until the component's own controller subscribes; children rendered by a parent have no channel to deliver to yet.
-
#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
Nil until the component's own controller subscribes; children rendered by a parent have no channel to deliver to yet.
10 11 12 |
# File 'lib/live_cable/component/broadcasting.rb', line 10 def broadcast(data) channel&.broadcast(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.
20 21 22 |
# File 'lib/live_cable/component/broadcasting.rb', line 20 def broadcast_ack broadcast({ _ack: true }) end |
#broadcast_destroy ⇒ Object
24 25 26 27 |
# File 'lib/live_cable/component/broadcasting.rb', line 24 def broadcast_destroy broadcast({ _status: 'destroy' }) @subscribed = false end |
#broadcast_render ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/live_cable/component/broadcasting.rb', line 29 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
14 15 16 |
# File 'lib/live_cable/component/broadcasting.rb', line 14 def broadcast_subscribe broadcast({ _status: 'subscribed', id: live_id }) end |