提交 6be2604a 编写于 作者: K Kasper Timm Hansen

Tune whitespace in README.md

* Realign `end` statements with the opening `class` statement.
* Pad JavaScript objects with spaces to match Rails styleguide and for consistency with other examples.
上级 63cdbf87
......@@ -187,7 +187,7 @@ class WebNotificationsChannel < ApplicationCable::Channel
def subscribed
stream_from "web_notifications_#{current_user.id}"
end
end
end
```
```coffeescript
......@@ -219,14 +219,14 @@ class ChatChannel < ApplicationCable::Channel
def subscribed
stream_from "chat_#{params[:room]}"
end
end
end
```
Pass an object as the first argument to `subscriptions.create`, and that object will become your params hash in your cable channel. The keyword `channel` is required.
```coffeescript
# Client-side which assumes you've already requested the right to send web notifications
App.cable.subscriptions.create {channel: "ChatChannel", room: "Best Room"},
App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" },
received: (data) ->
new Message data['sent_by'], body: data['body']
```
......@@ -257,11 +257,11 @@ end
```coffeescript
# Client-side which assumes you've already requested the right to send web notifications
sub = App.cable.subscriptions.create {channel: "ChatChannel", room: "Best Room"},
sub = App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" },
received: (data) ->
new Message data['sent_by'], body: data['body']
sub.send {sent_by: 'Peter', body: 'Hello Paul, thanks for the compliment.'}
sub.send { sent_by: 'Peter', body: 'Hello Paul, thanks for the compliment.' }
```
The rebroadcast will be received by all connected clients, _including_ the client that sent the message. Note that params are the same as they were when you subscribed to the channel.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册