aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/javascript/action_cable/index.js.erb
diff options
context:
space:
mode:
authorRichard Macklin <richard.github@nrm.com>2017-12-11 14:44:52 +0800
committerRichard Macklin <richard.github@nrm.com>2018-11-02 08:40:35 -0700
commit403c001c56e3980e624da2cb1e1e98d667499d40 (patch)
treefcdcb33626125f00dff1fc11a9447995f8b7abf4 /actioncable/app/javascript/action_cable/index.js.erb
parent7b0b37240a20c74197408ac3b53519e7e18347e9 (diff)
downloadrails-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/index.js.erb')
-rw-r--r--actioncable/app/javascript/action_cable/index.js.erb73
1 files changed, 46 insertions, 27 deletions
diff --git a/actioncable/app/javascript/action_cable/index.js.erb b/actioncable/app/javascript/action_cable/index.js.erb
index e0758dae72..a5fb5b4556 100644
--- a/actioncable/app/javascript/action_cable/index.js.erb
+++ b/actioncable/app/javascript/action_cable/index.js.erb
@@ -1,38 +1,57 @@
-#= export ActionCable
-#= require_self
-#= require ./action_cable/consumer
+/*
+ * decaffeinate suggestions:
+ * DS101: Remove unnecessary use of Array.from
+ * DS102: Remove unnecessary code created because of implicit returns
+ * DS104: Avoid inline assignments
+ * DS207: Consider shorter variations of null checks
+ * DS208: Avoid top-level this
+ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
+ */
+//= export ActionCable
+//= require_self
+//= require ./action_cable/consumer
-@ActionCable =
- INTERNAL: <%= ActionCable::INTERNAL.to_json %>
- WebSocket: window.WebSocket
- logger: window.console
+this.ActionCable = {
+ INTERNAL: <%= ActionCable::INTERNAL.to_json %>,
+ WebSocket: window.WebSocket,
+ logger: window.console,
- createConsumer: (url) ->
- url ?= @getConfig("url") ? @INTERNAL.default_mount_path
- new ActionCable.Consumer @createWebSocketURL(url)
+ createConsumer(url) {
+ if (url == null) { let left
+ url = (left = this.getConfig("url")) != null ? left : this.INTERNAL.default_mount_path }
+ return new ActionCable.Consumer(this.createWebSocketURL(url))
+ },
- getConfig: (name) ->
- element = document.head.querySelector("meta[name='action-cable-#{name}']")
- element?.getAttribute("content")
+ getConfig(name) {
+ const element = document.head.querySelector(`meta[name='action-cable-${name}']`)
+ return (element != null ? element.getAttribute("content") : undefined)
+ },
- createWebSocketURL: (url) ->
- if url and not /^wss?:/i.test(url)
- a = document.createElement("a")
+ createWebSocketURL(url) {
+ if (url && !/^wss?:/i.test(url)) {
+ const a = document.createElement("a")
a.href = url
- # Fix populating Location properties in IE. Otherwise, protocol will be blank.
+ // Fix populating Location properties in IE. Otherwise, protocol will be blank.
a.href = a.href
a.protocol = a.protocol.replace("http", "ws")
- a.href
- else
- url
+ return a.href
+ } else {
+ return url
+ }
+ },
- startDebugging: ->
- @debugging = true
+ startDebugging() {
+ return this.debugging = true
+ },
- stopDebugging: ->
- @debugging = null
+ stopDebugging() {
+ return this.debugging = null
+ },
- log: (messages...) ->
- if @debugging
+ log(...messages) {
+ if (this.debugging) {
messages.push(Date.now())
- @logger.log("[ActionCable]", messages...)
+ return this.logger.log("[ActionCable]", ...Array.from(messages))
+ }
+ }
+}