From dbe073aebf198493a1a162d314c49dfcd5dbbf1b Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 14 Jan 2019 11:32:56 -0800 Subject: Simplify ActionCable.createConsumer by using default argument --- actioncable/app/assets/javascripts/action_cable.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'actioncable/app/assets') diff --git a/actioncable/app/assets/javascripts/action_cable.js b/actioncable/app/assets/javascripts/action_cable.js index 65e32d6c3f..7710313c40 100644 --- a/actioncable/app/assets/javascripts/action_cable.js +++ b/actioncable/app/assets/javascripts/action_cable.js @@ -452,11 +452,8 @@ }; return Consumer; }(); - function createConsumer(url) { - if (url == null) { - var urlConfig = getConfig("url"); - url = urlConfig ? urlConfig : INTERNAL.default_mount_path; - } + function createConsumer() { + var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getConfig("url") || INTERNAL.default_mount_path; return new Consumer(createWebSocketURL(url)); } function getConfig(name) { -- cgit v1.2.3 From 6320916513891938f7d2f0b5c9c36968ee2d8705 Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 14 Jan 2019 11:35:04 -0800 Subject: Simplify ActionCable.getConfig, Connection#getProtocol, and Connection#close by relying on the implicit undefined return value --- actioncable/app/assets/javascripts/action_cable.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'actioncable/app/assets') diff --git a/actioncable/app/assets/javascripts/action_cable.js b/actioncable/app/assets/javascripts/action_cable.js index 7710313c40..d860fba76e 100644 --- a/actioncable/app/assets/javascripts/action_cable.js +++ b/actioncable/app/assets/javascripts/action_cable.js @@ -191,8 +191,8 @@ if (!allowReconnect) { this.monitor.stop(); } - if (this.isActive()) { - return this.webSocket ? this.webSocket.close() : undefined; + if (this.isActive() && this.webSocket) { + return this.webSocket.close(); } }; Connection.prototype.reopen = function reopen() { @@ -211,7 +211,9 @@ } }; Connection.prototype.getProtocol = function getProtocol() { - return this.webSocket ? this.webSocket.protocol : undefined; + if (this.webSocket) { + return this.webSocket.protocol; + } }; Connection.prototype.isOpen = function isOpen() { return this.isState("open"); @@ -458,7 +460,9 @@ } function getConfig(name) { var element = document.head.querySelector("meta[name='action-cable-" + name + "']"); - return element ? element.getAttribute("content") : undefined; + if (element) { + return element.getAttribute("content"); + } } function createWebSocketURL(url) { if (url && !/^wss?:/i.test(url)) { -- cgit v1.2.3 From 739f88e52ec9d673e23f41545d55626351ce24eb Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 14 Jan 2019 11:36:32 -0800 Subject: Simplify `this.isActive() && this.webSocket` into `this.isActive()` in Connection#close. We can do this because `isActive()` can only return `true` if `this.webSocket` is truthy. (We can't have an active connection without having instantiated a WebSocket. This is confirmed in the code: Connection#isActive calls Connection#isState which calls Connection#getState, which checks if `this.webSocket` is truthy and returns `null` otherwise.) --- actioncable/app/assets/javascripts/action_cable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actioncable/app/assets') diff --git a/actioncable/app/assets/javascripts/action_cable.js b/actioncable/app/assets/javascripts/action_cable.js index d860fba76e..a68c76f299 100644 --- a/actioncable/app/assets/javascripts/action_cable.js +++ b/actioncable/app/assets/javascripts/action_cable.js @@ -191,7 +191,7 @@ if (!allowReconnect) { this.monitor.stop(); } - if (this.isActive() && this.webSocket) { + if (this.isActive()) { return this.webSocket.close(); } }; -- cgit v1.2.3