mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add new convention method for performing channel actions
This commit is contained in:
parent
4aa20012a2
commit
0e4c2df1e1
1 changed files with 7 additions and 0 deletions
|
@ -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)
|
Loading…
Reference in a new issue