Module: DigitalCable::Broadcaster

Included in:
Reflex
Defined in:
lib/digital_cable/broadcaster.rb

Constant Summary collapse

OPERATIONS =
[
  :add_css_class,
  :console_log,
  :dispatch_event,
  :inner_html,
  :insert_adjacent_html,
  :insert_adjacent_text,
  :morph,
  :notification,
  :outer_html,
  :push_state,
  :remove,
  :remove_attribute,
  :remove_css_class,
  :set_attribute,
  :set_cookie,
  :set_dataset_property,
  :set_focus,
  :set_property,
  :set_style,
  :set_styles,
  :set_value,
  :text_content
]

Instance Method Summary collapse

Instance Method Details

#broadcast(identifier, method:, options:) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/digital_cable/broadcaster.rb', line 31

def broadcast(identifier, method:, options:)
  verify_method!(method)

  ActionCable.server.broadcast identifier, {
    "digitalCable" => true,
    "operation" => { method: method.to_s.camelize(:lower), options: options }
  }
end

#broadcast_to(identifier, model, method:, options:) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/digital_cable/broadcaster.rb', line 40

def broadcast_to(identifier, model, method:, options:)
  verify_method!(method)

  identifier.broadcast_to model, {
    "digitalCable" => true,
    "operation" => { method: method.to_s.camelize(:lower), options: options }
  }
end