diff options
Diffstat (limited to 'lib/assets')
-rw-r--r-- | lib/assets/javascripts/channel.js.coffee | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/assets/javascripts/channel.js.coffee b/lib/assets/javascripts/channel.js.coffee index 058bcc03aa..2f07affb19 100644 --- a/lib/assets/javascripts/channel.js.coffee +++ b/lib/assets/javascripts/channel.js.coffee @@ -1,6 +1,6 @@ class @Cable.Channel constructor: (params = {}) -> - @channelName ?= @underscore @constructor.name + @channelName ?= "#{@underscore(@constructor.name)}_channel" params['channel'] = @channelName @channelIdentifier = JSON.stringify params @@ -11,6 +11,7 @@ class @Cable.Channel onReceiveData: @received }) + connected: => # Override in the subclass @@ -20,8 +21,14 @@ class @Cable.Channel received: (data) => # Override in the subclass + # Perform a channel action with the optional data passed as an attribute + perform: (action, data = {}) -> + data.action = action + cable.sendData @channelIdentifier, JSON.stringify data + 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 |