Class: SvelteOnRails::ActionCable
- Inherits:
-
Object
- Object
- SvelteOnRails::ActionCable
- Defined in:
- lib/svelte_on_rails/action_cable.rb
Class Method Summary collapse
- .dispatch(component = nil, event_detail = nil, event: 'stream-action', selector: nil, channel: nil) ⇒ Object
- .dispatch_by_selector(selector, event_detail = nil, event: 'stream-action', channel: nil) ⇒ Object
- .require_channel(channel) ⇒ Object
- .svelte_on_rails_configs ⇒ Object
Class Method Details
.dispatch(component = nil, event_detail = nil, event: 'stream-action', selector: nil, channel: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/svelte_on_rails/action_cable.rb', line 3 def self.dispatch(component = nil, event_detail = nil, event: 'stream-action', selector: nil, channel: nil) utils = SvelteOnRails::Lib::Utils conf = SvelteOnRails::Configuration.instance paths = utils.component_paths_uncached(component, nil) _comp = if component paths[:vite_path] end _channel = require_channel(svelte_on_rails_configs[:channel] || channel) if event != 'stream-action' && !selector raise "Another event name than the default one is only possible together with a selector" end args = { eventDetail: event_detail, component: _comp, event: event, selector: selector } ::ActionCable.server.broadcast( _channel, args ) end |
.dispatch_by_selector(selector, event_detail = nil, event: 'stream-action', channel: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/svelte_on_rails/action_cable.rb', line 33 def self.dispatch_by_selector(selector, event_detail = nil, event: 'stream-action', channel: nil) _channel = require_channel(svelte_on_rails_configs[:channel] || channel) if event != 'stream-action' && !selector raise "Another event name than the default one is only possible together with a selector" end args = { eventDetail: event_detail, component: ':false:', event: event, selector: selector } ::ActionCable.server.broadcast( _channel, args ) end |
.require_channel(channel) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/svelte_on_rails/action_cable.rb', line 63 def self.require_channel(channel) unless channel.present? raise 'Missing attribute or configuration: action_cable/channel' end channel end |
.svelte_on_rails_configs ⇒ Object
57 58 59 60 61 |
# File 'lib/svelte_on_rails/action_cable.rb', line 57 def self.svelte_on_rails_configs cnf = SvelteOnRails::Configuration.instance.configs[:action_cable] raise 'ActionCable not configured for SvelteOnRails' if cnf.nil? cnf end |