aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/rails/generators/channel/templates/assets
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-05-21 08:52:43 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-05-21 08:52:43 -0300
commitdb312a9fb04097e7d584d24dd446aac7dea7e11f (patch)
treeeba6c8973aa6046188b2c38e7ac811d833501138 /actioncable/lib/rails/generators/channel/templates/assets
parent7087ff99071cd29f1d07e5298dbc204bede6ca86 (diff)
parent63ac6255ba3553b529f4b23846ec756b7a7a746d (diff)
downloadrails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.gz
rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.bz2
rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.zip
Merge pull request #24918 from prathamesh-sonpatki/cable-assets
Cable: Generate .js or .coffee files while generating channel as per the javascript engine of the application
Diffstat (limited to 'actioncable/lib/rails/generators/channel/templates/assets')
-rw-r--r--actioncable/lib/rails/generators/channel/templates/assets/channel.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/actioncable/lib/rails/generators/channel/templates/assets/channel.js b/actioncable/lib/rails/generators/channel/templates/assets/channel.js
new file mode 100644
index 0000000000..ab0e68b11a
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/assets/channel.js
@@ -0,0 +1,18 @@
+App.<%= class_name.underscore %> = App.cable.subscriptions.create("<%= class_name %>Channel", {
+ connected: function() {
+ // Called when the subscription is ready for use on the server
+ },
+
+ disconnected: function() {
+ // Called when the subscription has been terminated by the server
+ },
+
+ received: function(data) {
+ // Called when there's incoming data on the websocket for this channel
+ }<%= actions.any? ? ",\n" : '' %>
+<% actions.each do |action| -%>
+ <%=action %>: function() {
+ return this.perform('<%= action %>');
+ }<%= action == actions[-1] ? '' : ",\n" %>
+<% end -%>
+});