Skip to content

Commit fb1e73e

Browse files
committed
Move ActionCable channels to application pack
1 parent 57a76f7 commit fb1e73e

8 files changed

Lines changed: 31 additions & 25 deletions

File tree

app/assets/javascripts/cable.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/assets/javascripts/channels/chat.coffee

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import consumer from "./consumer"
2+
3+
consumer.subscriptions.create("ChatChannel", {
4+
connected: function() {
5+
// Called when the subscription is ready for use on the server
6+
},
7+
8+
disconnected: function() {
9+
// Called when the subscription has been terminated by the server
10+
},
11+
12+
received: function(data) {
13+
// Called when there's incoming data on the websocket for this channel
14+
},
15+
16+
speak: function() {
17+
return this.perform('speak')
18+
}
19+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createConsumer } from "@rails/actioncable"
2+
3+
export default createConsumer()

app/javascript/channels/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const channels = require.context('.', true, /_channel\.js$/)
2+
channels.keys().forEach(channels)

app/javascript/packs/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
require("@rails/ujs").start()
1111
require("turbolinks").start()
1212
require("@rails/activestorage").start()
13+
require("channels")

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "webpacker-rails-5-2",
33
"private": true,
44
"dependencies": {
5+
"@rails/actioncable": "^6.0.0-alpha",
56
"@rails/activestorage": "^6.0.0-alpha",
67
"@rails/ujs": "^6.0.0-alpha",
78
"@rails/webpacker": "3.5",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@rails/actioncable@^6.0.0-alpha":
6+
version "6.0.0-alpha"
7+
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.0.0-alpha.tgz#84be50626a43fe431789243c6b13c14f922bf048"
8+
integrity sha512-hBaruc8FMus0EuLL2LzPHHZpQUHzNrvDzmy9EN03P5K4DQR43FTdksCu77kbx2TrKlrvjnJ1PBbcx87jGotykw==
9+
510
"@rails/activestorage@^6.0.0-alpha":
611
version "6.0.0-alpha"
712
resolved "https://registry.yarnpkg.com/@rails/activestorage/-/activestorage-6.0.0-alpha.tgz#6eb6c0f49bcaa4ad68fcd13a750b9a17f76f086f"

0 commit comments

Comments
 (0)