Skip to content

Commit 39421d6

Browse files
committed
undo prettier
1 parent 201fd83 commit 39421d6

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

web_src/js/htmx.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
import * as htmx from "htmx.org";
2-
import { showErrorToast } from "./modules/toast.js";
3-
import "htmx.org/dist/ext/ws.js";
1+
import * as htmx from 'htmx.org';
2+
import { showErrorToast } from './modules/toast.js';
3+
import 'htmx.org/dist/ext/ws.js';
44

55
// https://github.com/bigskysoftware/idiomorph#htmx
6-
import "idiomorph/dist/idiomorph-ext.js";
6+
import 'idiomorph/dist/idiomorph-ext.js';
77

88
// https://htmx.org/reference/#config
9-
htmx.config.requestClass = "is-loading";
9+
htmx.config.requestClass = 'is-loading';
1010
htmx.config.scrollIntoViewOnBoost = false;
1111

1212
// https://htmx.org/events/#htmx:sendError
13-
document.body.addEventListener("htmx:sendError", (e) => {
13+
document.body.addEventListener('htmx:sendError', (e) => {
1414
// TODO: add translations
1515
showErrorToast(`Network error when calling ${e.detail.requestConfig.path}`);
1616
});
1717

1818
// https://htmx.org/events/#htmx:responseError
19-
document.body.addEventListener("htmx:responseError", (e) => {
19+
document.body.addEventListener('htmx:responseError', (e) => {
2020
// TODO: add translations
2121
showErrorToast(
2222
`Error ${e.detail.xhr.status} when calling ${e.detail.requestConfig.path}`
2323
);
2424
});
2525

26-
// eslint-disable-next-line no-import-assign
26+
let webSocket;
27+
28+
// TODO: move websocket creation to shared webworker
2729
htmx.createWebSocket = (url) => {
28-
// TODO: reuse websocket from shared webworker
29-
const sock = new WebSocket(url, []);
30-
sock.binaryType = htmx.config.wsBinaryType;
31-
g;
32-
return sock;
30+
if (![0, 1].includes(webSocket?.readyState)) return webSocket;
31+
const ws = new WebSocket(url, []);
32+
ws.binaryType = htmx.config.wsBinaryType;
33+
webSocket = ws;
34+
return ws;
3335
};
34-
document.body.addEventListener("htmx:wsOpen", (e) => {
36+
37+
document.body.addEventListener('htmx:wsOpen', (e) => {
3538
const socket = e.detail.socketWrapper;
3639
socket.send(
37-
JSON.stringify({ action: "subscribe", data: { url: window.location.href } })
40+
JSON.stringify({ action: 'subscribe', data: { url: window.location.href } })
3841
);
3942
});

0 commit comments

Comments
 (0)