From d03177ffbccb5b30217448d526f1e9aa1fa24297 Mon Sep 17 00:00:00 2001 From: rmacklin <1863540+rmacklin@users.noreply.github.com> Date: Tue, 2 Apr 2019 14:04:43 -0700 Subject: 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 --- actioncable/app/javascript/action_cable/consumer.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'actioncable/app/javascript/action_cable/consumer.js') 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 } } -- cgit v1.2.3