aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app
diff options
context:
space:
mode:
authorrmacklin <1863540+rmacklin@users.noreply.github.com>2019-04-02 14:04:43 -0700
committerKasper Timm Hansen <kaspth@gmail.com>2019-04-02 23:04:43 +0200
commitd03177ffbccb5b30217448d526f1e9aa1fa24297 (patch)
treec5d9e71dc6126803f357d00f90944d19c37fb5c0 /actioncable/app
parent2c4dab11d1db468f54b409250f3c39ff555e8d50 (diff)
downloadrails-d03177ffbccb5b30217448d526f1e9aa1fa24297.tar.gz
rails-d03177ffbccb5b30217448d526f1e9aa1fa24297.tar.bz2
rails-d03177ffbccb5b30217448d526f1e9aa1fa24297.zip
Simplify ActionCable.createWebSocketURL and realphabetize exports (#35810)
* Remove unnecessary variable from ActionCable.createWebSocketURL * Improve ActionCable test by creating the Consumer before reassigning URL With this change, the test now actually verifies that the Consumer's url property changes dynamically (from testURL to `${testURL}foo`). * Fix alphabetization of ActionCable exports
Diffstat (limited to 'actioncable/app')
-rw-r--r--actioncable/app/assets/javascripts/action_cable.js12
-rw-r--r--actioncable/app/javascript/action_cable/consumer.js10
-rw-r--r--actioncable/app/javascript/action_cable/index.js2
3 files changed, 14 insertions, 10 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable.js b/actioncable/app/assets/javascripts/action_cable.js
index 029c7567ce..8349361405 100644
--- a/actioncable/app/assets/javascripts/action_cable.js
+++ b/actioncable/app/assets/javascripts/action_cable.js
@@ -477,15 +477,17 @@
return Consumer;
}();
function createWebSocketURL(url) {
- var webSocketURL = typeof url === "function" ? url() : url;
- if (webSocketURL && !/^wss?:/i.test(webSocketURL)) {
+ if (typeof url === "function") {
+ url = url();
+ }
+ if (url && !/^wss?:/i.test(url)) {
var a = document.createElement("a");
- a.href = webSocketURL;
+ a.href = url;
a.href = a.href;
a.protocol = a.protocol.replace("http", "ws");
return a.href;
} else {
- return webSocketURL;
+ return url;
}
}
function createConsumer() {
@@ -505,8 +507,8 @@
exports.Subscription = Subscription;
exports.Subscriptions = Subscriptions;
exports.adapters = adapters;
- exports.logger = logger;
exports.createWebSocketURL = createWebSocketURL;
+ exports.logger = logger;
exports.createConsumer = createConsumer;
exports.getConfig = getConfig;
Object.defineProperty(exports, "__esModule", {
diff --git a/actioncable/app/javascript/action_cable/consumer.js b/actioncable/app/javascript/action_cable/consumer.js
index 51f3b60980..e2e0dea8b5 100644
--- a/actioncable/app/javascript/action_cable/consumer.js
+++ b/actioncable/app/javascript/action_cable/consumer.js
@@ -58,16 +58,18 @@ export default class Consumer {
}
export function createWebSocketURL(url) {
- const webSocketURL = typeof url === "function" ? url() : url
+ if (typeof url === "function") {
+ url = url()
+ }
- if (webSocketURL && !/^wss?:/i.test(webSocketURL)) {
+ if (url && !/^wss?:/i.test(url)) {
const a = document.createElement("a")
- a.href = webSocketURL
+ a.href = url
// Fix populating Location properties in IE. Otherwise, protocol will be blank.
a.href = a.href
a.protocol = a.protocol.replace("http", "ws")
return a.href
} else {
- return webSocketURL
+ return url
}
}
diff --git a/actioncable/app/javascript/action_cable/index.js b/actioncable/app/javascript/action_cable/index.js
index d484d99179..848b5631d6 100644
--- a/actioncable/app/javascript/action_cable/index.js
+++ b/actioncable/app/javascript/action_cable/index.js
@@ -15,8 +15,8 @@ export {
Subscription,
Subscriptions,
adapters,
- logger,
createWebSocketURL,
+ logger,
}
export function createConsumer(url = getConfig("url") || INTERNAL.default_mount_path) {