diff options
author | Javan Makhmali <javan@javan.us> | 2015-06-23 18:16:31 -0400 |
---|---|---|
committer | Javan Makhmali <javan@javan.us> | 2015-06-23 18:16:31 -0400 |
commit | b5e0e58fe17b9cf5f53688ee1fac74772e565da1 (patch) | |
tree | 4df34d5a8a59a09722d36edf1ddc64ea4c7fa31a /lib | |
parent | a66c56210c844ba51452fbf7a0aa01175ea3eb6f (diff) | |
download | rails-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')
-rw-r--r-- | lib/assets/javascripts/channel.js.coffee | 13 |
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 |