diff options
author | Javan Makhmali <javan@javan.us> | 2015-06-24 09:24:15 -0400 |
---|---|---|
committer | Javan Makhmali <javan@javan.us> | 2015-06-24 09:24:15 -0400 |
commit | 2ecc9b513821a7ebf365f42f2061e4e4300cf6d3 (patch) | |
tree | 4df34d5a8a59a09722d36edf1ddc64ea4c7fa31a /lib/assets/javascripts | |
parent | a66c56210c844ba51452fbf7a0aa01175ea3eb6f (diff) | |
parent | b5e0e58fe17b9cf5f53688ee1fac74772e565da1 (diff) | |
download | rails-2ecc9b513821a7ebf365f42f2061e4e4300cf6d3.tar.gz rails-2ecc9b513821a7ebf365f42f2061e4e4300cf6d3.tar.bz2 rails-2ecc9b513821a7ebf365f42f2061e4e4300cf6d3.zip |
Merge pull request #1 from basecamp/required-channel-name
Require Cable.Channel constructors to define their channel name
Diffstat (limited to 'lib/assets/javascripts')
-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 |