aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/javascript/action_cable/index.js.erb
diff options
context:
space:
mode:
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))
+ }
+ }
+}