diff options
author | Richard Macklin <richard.github@nrm.com> | 2017-12-11 14:44:52 +0800 |
---|---|---|
committer | Richard Macklin <richard.github@nrm.com> | 2018-11-02 08:40:35 -0700 |
commit | 403c001c56e3980e624da2cb1e1e98d667499d40 (patch) | |
tree | fcdcb33626125f00dff1fc11a9447995f8b7abf4 /actioncable/app/javascript/action_cable/consumer.js | |
parent | 7b0b37240a20c74197408ac3b53519e7e18347e9 (diff) | |
download | rails-403c001c56e3980e624da2cb1e1e98d667499d40.tar.gz rails-403c001c56e3980e624da2cb1e1e98d667499d40.tar.bz2 rails-403c001c56e3980e624da2cb1e1e98d667499d40.zip |
Run decaffeinate on action_cable/*.js
Using [decaffeinate], we have converted these files from coffeescript
syntax to ES2015 syntax. Decaffeinate is very conservative in the
conversion process to ensure exact coffeescript semantics are preserved.
Most of the time, it's safe to clean up the code, and decaffeinate has
left suggestions regarding potential cleanups we can take. I'll tackle
those cleanups separately.
After running decaffeinate, I ran:
```
eslint --fix app/javascript
```
using the eslint configuration from ActiveStorage to automatically
correct lint violations in the decaffeinated output. This removed 189
extra semicolons and changed one instance of single quotes to double
quotes.
Note: decaffeinate and eslint can't parse ERB syntax. So I worked around
that by temporarily quoting the ERB:
```diff
@ActionCable =
- INTERNAL: <%= ActionCable::INTERNAL.to_json %>
+ INTERNAL: "<%= ActionCable::INTERNAL.to_json %>"
WebSocket: window.WebSocket
logger: window.console
```
and then removing those quotes after running decaffeinate and eslint.
[decaffeinate]: https://github.com/decaffeinate/decaffeinate
Diffstat (limited to 'actioncable/app/javascript/action_cable/consumer.js')
-rw-r--r-- | actioncable/app/javascript/action_cable/consumer.js | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/actioncable/app/javascript/action_cable/consumer.js b/actioncable/app/javascript/action_cable/consumer.js index 3298be717f..c2a851b876 100644 --- a/actioncable/app/javascript/action_cable/consumer.js +++ b/actioncable/app/javascript/action_cable/consumer.js @@ -1,46 +1,59 @@ -#= require ./connection -#= require ./subscriptions -#= require ./subscription +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +//= require ./connection +//= require ./subscriptions +//= require ./subscription -# The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established, -# the ActionCable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates. -# The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription -# method. -# -# The following example shows how this can be setup: -# -# @App = {} -# App.cable = ActionCable.createConsumer "ws://example.com/accounts/1" -# App.appearance = App.cable.subscriptions.create "AppearanceChannel" -# -# For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription. -# -# When a consumer is created, it automatically connects with the server. -# -# To disconnect from the server, call -# -# App.cable.disconnect() -# -# and to restart the connection: -# -# App.cable.connect() -# -# Any channel subscriptions which existed prior to disconnecting will -# automatically resubscribe. -class ActionCable.Consumer - constructor: (@url) -> - @subscriptions = new ActionCable.Subscriptions this - @connection = new ActionCable.Connection this +// The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established, +// the ActionCable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates. +// The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription +// method. +// +// The following example shows how this can be setup: +// +// @App = {} +// App.cable = ActionCable.createConsumer "ws://example.com/accounts/1" +// App.appearance = App.cable.subscriptions.create "AppearanceChannel" +// +// For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription. +// +// When a consumer is created, it automatically connects with the server. +// +// To disconnect from the server, call +// +// App.cable.disconnect() +// +// and to restart the connection: +// +// App.cable.connect() +// +// Any channel subscriptions which existed prior to disconnecting will +// automatically resubscribe. +ActionCable.Consumer = class Consumer { + constructor(url) { + this.url = url + this.subscriptions = new ActionCable.Subscriptions(this) + this.connection = new ActionCable.Connection(this) + } - send: (data) -> - @connection.send(data) + send(data) { + return this.connection.send(data) + } - connect: -> - @connection.open() + connect() { + return this.connection.open() + } - disconnect: -> - @connection.close(allowReconnect: false) + disconnect() { + return this.connection.close({allowReconnect: false}) + } - ensureActiveConnection: -> - unless @connection.isActive() - @connection.open() + ensureActiveConnection() { + if (!this.connection.isActive()) { + return this.connection.open() + } + } +} |