Skip to content

Commit

Permalink
Merge pull request #346 from leastbad/parent_channel
Browse files Browse the repository at this point in the history
Move StimulusReflex::Channel to app/ and allow for a configurable parent channel
  • Loading branch information
leastbad authored Nov 1, 2020
2 parents f415641 + ac84647 commit 4dfda40
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
def initialize(connection, identifier, params = {})
super
application_channel = Rails.root.join("app", "channels", "application_cable", "channel.rb")
require application_channel if File.exist?(application_channel)
end
end
end

class StimulusReflex::Channel < ApplicationCable::Channel
class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.constantize
def stream_name
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

StimulusReflex.configure do |config|
# configuration options explained here:
# Short description of what the config variable does, best with the available options.
# config.example = true
# Override the parent class that the StimulusReflex ActionCable channel inherits from
# config.parent_channel = "ApplicationCable::Channel"
end
1 change: 0 additions & 1 deletion lib/stimulus_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require "stimulus_reflex/configuration"
require "stimulus_reflex/reflex"
require "stimulus_reflex/element"
require "stimulus_reflex/channel"
require "stimulus_reflex/sanity_checker"
require "stimulus_reflex/broadcasters/broadcaster"
require "stimulus_reflex/broadcasters/nothing_broadcaster"
Expand Down
4 changes: 2 additions & 2 deletions lib/stimulus_reflex/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def configuration
end

class Configuration
attr_accessor :example # put your attr_accessors here, like `attr_accessor: debug`, remove this line when you do.
attr_accessor :parent_channel

def initialize
@example = true # put your defaults here like `@debug = true, remove this line when you do.
@parent_channel = "ApplicationCable::Channel"
end
end
end

0 comments on commit 4dfda40

Please sign in to comment.