mirror of https://github.com/rails/rails
Merge pull request #34934 from rmacklin/simplify-actioncable-methods-after-decaffeination
Clean up ActionCable JS a bit more after the CoffeeScript conversion
This commit is contained in:
commit
0ffafd475b
|
@ -192,7 +192,7 @@
|
|||
this.monitor.stop();
|
||||
}
|
||||
if (this.isActive()) {
|
||||
return this.webSocket ? this.webSocket.close() : undefined;
|
||||
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");
|
||||
|
@ -452,16 +454,15 @@
|
|||
};
|
||||
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) {
|
||||
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)) {
|
||||
|
|
|
@ -44,7 +44,9 @@ class Connection {
|
|||
|
||||
close({allowReconnect} = {allowReconnect: true}) {
|
||||
if (!allowReconnect) { this.monitor.stop() }
|
||||
if (this.isActive()) { return (this.webSocket ? this.webSocket.close() : undefined) }
|
||||
if (this.isActive()) {
|
||||
return this.webSocket.close()
|
||||
}
|
||||
}
|
||||
|
||||
reopen() {
|
||||
|
@ -65,7 +67,9 @@ class Connection {
|
|||
}
|
||||
|
||||
getProtocol() {
|
||||
return (this.webSocket ? this.webSocket.protocol : undefined)
|
||||
if (this.webSocket) {
|
||||
return this.webSocket.protocol
|
||||
}
|
||||
}
|
||||
|
||||
isOpen() {
|
||||
|
|
|
@ -18,17 +18,15 @@ export {
|
|||
logger,
|
||||
}
|
||||
|
||||
export function createConsumer(url) {
|
||||
if (url == null) {
|
||||
const urlConfig = getConfig("url")
|
||||
url = (urlConfig ? urlConfig : INTERNAL.default_mount_path)
|
||||
}
|
||||
export function createConsumer(url = getConfig("url") || INTERNAL.default_mount_path) {
|
||||
return new Consumer(createWebSocketURL(url))
|
||||
}
|
||||
|
||||
export function getConfig(name) {
|
||||
const element = document.head.querySelector(`meta[name='action-cable-${name}']`)
|
||||
return (element ? element.getAttribute("content") : undefined)
|
||||
if (element) {
|
||||
return element.getAttribute("content")
|
||||
}
|
||||
}
|
||||
|
||||
export function createWebSocketURL(url) {
|
||||
|
|
Loading…
Reference in New Issue