1
0
Fork 0
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:
David Heinemeier Hansson 2015-06-20 16:01:44 +02:00
parent 4aa20012a2
commit 0e4c2df1e1

View file

@ -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)