Skip to content

Commit

Permalink
Move ActionCable channels to application pack
Browse files Browse the repository at this point in the history
  • Loading branch information
calleluks committed Feb 1, 2019
1 parent 57a76f7 commit fb1e73e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
13 changes: 0 additions & 13 deletions app/assets/javascripts/cable.js

This file was deleted.

12 changes: 0 additions & 12 deletions app/assets/javascripts/channels/chat.coffee

This file was deleted.

19 changes: 19 additions & 0 deletions app/javascript/channels/chat_channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import consumer from "./consumer"

consumer.subscriptions.create("ChatChannel", {
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
},

speak: function() {
return this.perform('speak')
}
})
3 changes: 3 additions & 0 deletions app/javascript/channels/consumer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createConsumer } from "@rails/actioncable"

export default createConsumer()
2 changes: 2 additions & 0 deletions app/javascript/channels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "webpacker-rails-5-2",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0-alpha",
"@rails/activestorage": "^6.0.0-alpha",
"@rails/ujs": "^6.0.0-alpha",
"@rails/webpacker": "3.5",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@rails/actioncable@^6.0.0-alpha":
version "6.0.0-alpha"
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.0.0-alpha.tgz#84be50626a43fe431789243c6b13c14f922bf048"
integrity sha512-hBaruc8FMus0EuLL2LzPHHZpQUHzNrvDzmy9EN03P5K4DQR43FTdksCu77kbx2TrKlrvjnJ1PBbcx87jGotykw==

"@rails/activestorage@^6.0.0-alpha":
version "6.0.0-alpha"
resolved "https://registry.yarnpkg.com/@rails/activestorage/-/activestorage-6.0.0-alpha.tgz#6eb6c0f49bcaa4ad68fcd13a750b9a17f76f086f"
Expand Down

0 comments on commit fb1e73e

Please sign in to comment.