Class: ActionView::Component::Live::LiveUpdater
- Inherits:
-
Object
- Object
- ActionView::Component::Live::LiveUpdater
- Defined in:
- app/models/action_view/component/live/live_updater.rb
Class Method Summary collapse
Class Method Details
.subscribe(model, component_name) ⇒ Object
17 18 19 20 |
# File 'app/models/action_view/component/live/live_updater.rb', line 17 def subscribe(model, component_name) subscriptions[model] ||= [] subscriptions[model] << component_name end |
.subscriptions ⇒ Object
22 23 24 |
# File 'app/models/action_view/component/live/live_updater.rb', line 22 def subscriptions @subscriptions ||= {} end |
.update(model) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/action_view/component/live/live_updater.rb', line 6 def update(model) model_name = model.class.name return unless subscriptions[model_name].present? subscriptions[model_name].each do |component_name| locals = {model_name.underscore.to_sym => model} body = ApplicationController.render template: 'live', layout: false, locals: {component: component_name, locals: locals} LiveChannel.broadcast_to "#{component_name}:#{model.id}", body: body end end |