Skip to content

Commit 017c7f4

Browse files
y-yagikaspth
authored andcommitted
change cable.coffee to cable.js [ci skip]
In rails#23935, cable file was to be provided by the javascript instead of coffeescript, doc was also been modified to use javascript.
1 parent 692715e commit 017c7f4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

actioncable/README.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@ end
8686

8787
The client-side needs to setup a consumer instance of this connection. That's done like so:
8888

89-
```coffeescript
90-
# app/assets/javascripts/cable.coffee
91-
#= require action_cable
89+
```js
90+
// app/assets/javascripts/cable.js
91+
//= require action_cable
92+
//= require_self
93+
//= require_tree ./channels
94+
95+
(function() {
96+
this.App || (this.App = {});
9297

93-
@App = {}
94-
App.cable = ActionCable.createConsumer("ws://cable.example.com")
98+
App.cable = ActionCable.createConsumer("ws://cable.example.com");
99+
}).call(this);
95100
```
96101

97102
The `ws://cable.example.com` address must point to your Action Cable server(s), and it

guides/source/action_cable_overview.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ established using the following Javascript, which is generated by default in Rai
142142

143143
#### Connect Consumer
144144

145-
```coffeescript
146-
# app/assets/javascripts/cable.coffee
147-
#= require action_cable
145+
```js
146+
// app/assets/javascripts/cable.js
147+
//= require action_cable
148+
//= require_self
149+
//= require_tree ./channels
150+
151+
(function() {
152+
this.App || (this.App = {});
148153

149-
@App = {}
150-
App.cable = ActionCable.createConsumer()
154+
App.cable = ActionCable.createConsumer();
155+
}).call(this);
151156
```
152157

153158
This will ready a consumer that'll connect against /cable on your server by default.
@@ -414,7 +419,7 @@ App.cable.subscriptions.create "AppearanceChannel",
414419
```
415420

416421
##### Client-Server Interaction
417-
1. **Client** establishes a connection with the **Server** via `App.cable = ActionCable.createConsumer("ws://cable.example.com")`. [*` cable.coffee`*] The **Server** identified this connection instance by `current_user`.
422+
1. **Client** establishes a connection with the **Server** via `App.cable = ActionCable.createConsumer("ws://cable.example.com")`. [*` cable.js`*] The **Server** identified this connection instance by `current_user`.
418423
2. **Client** initiates a subscription to the `Appearance Channel` for their connection via `App.cable.subscriptions.create "AppearanceChannel"`. [*`appearance.coffee`*]
419424
3. **Server** recognizes a new subscription has been initiated for `AppearanceChannel` channel performs the `subscribed` callback, which calls the `appear` method on the `current_user`. [*`appearance_channel.rb`*]
420425
4. **Client** recognizes that a subscription has been established and calls `connected` [*`appearance.coffee`*] which in turn calls `@install` and `@appear`. `@appear` calls`AppearanceChannel#appear(data)` on the server, and supplies a data hash of `appearing_on: $("main").data("appearing-on")`. This is possible because the server-side channel instance will automatically expose the public methods declared on the class (minus the callbacks), so that these can be reached as remote procedure calls via a subscription's `perform` method.

0 commit comments

Comments
 (0)