aboutsummaryrefslogtreecommitdiffstats
path: root/lib/assets/javascripts
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2015-06-23 18:16:31 -0400
committerJavan Makhmali <javan@javan.us>2015-06-23 18:16:31 -0400
commitb5e0e58fe17b9cf5f53688ee1fac74772e565da1 (patch)
tree4df34d5a8a59a09722d36edf1ddc64ea4c7fa31a /lib/assets/javascripts
parenta66c56210c844ba51452fbf7a0aa01175ea3eb6f (diff)
downloadrails-b5e0e58fe17b9cf5f53688ee1fac74772e565da1.tar.gz
rails-b5e0e58fe17b9cf5f53688ee1fac74772e565da1.tar.bz2
rails-b5e0e58fe17b9cf5f53688ee1fac74772e565da1.zip
Require Cable.Channel constructors to define their channel name
Function.name is not widely supported, and a function's name can be mangled by a minifier making it an unreliable property to infer the channel name from
Diffstat (limited to 'lib/assets/javascripts')
-rw-r--r--lib/assets/javascripts/channel.js.coffee13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/assets/javascripts/channel.js.coffee b/lib/assets/javascripts/channel.js.coffee
index 2f07affb19..c972334140 100644
--- a/lib/assets/javascripts/channel.js.coffee
+++ b/lib/assets/javascripts/channel.js.coffee
@@ -1,9 +1,12 @@
class @Cable.Channel
constructor: (params = {}) ->
- @channelName ?= "#{@underscore(@constructor.name)}_channel"
+ {channelName} = @constructor
- params['channel'] = @channelName
- @channelIdentifier = JSON.stringify params
+ if channelName?
+ params['channel'] = channelName
+ @channelIdentifier = JSON.stringify params
+ else
+ throw new Error "This channel's constructor is missing the required 'channelName' property"
cable.subscribe(@channelIdentifier, {
onConnect: @connected
@@ -28,7 +31,3 @@ class @Cable.Channel
send: (data) ->
cable.sendData @channelIdentifier, JSON.stringify data
-
-
- underscore: (value) ->
- value.replace(/[A-Z]/g, (match) => "_#{match.toLowerCase()}").substr(1) \ No newline at end of file