4 ms·
>https://github.com/bigskysoftware/htmx/blob/1242977d11bebe56dfe612346d668b37d1a38a24/src/htmx.js#L4210 https://github.com/bigskysoftware/htmx/blob/1242977d11be
by angra_mainyu 2y ago
>https://github.com/bigskysoftware/htmx/blob/1242977d11bebe56dfe612346d668b37d1a38a24/src/htmx.js#L4210 https://github.com/bigskysoftware/htmx/blob/1242977d11bebe56...
This seems to be a scenario where switch/case blocks could make the elif-trees a bit easier to read.
Also, the code could use some care about not going so deep into the Vs:
// request headers
if (requestAttrValues.noHeaders) {
// ignore all headers
} else {
for (const header in headers) {
if (headers.hasOwnProperty(header)) {
const headerValue = headers[header]
safelySetHeaderValue(xhr, header, headerValue)
}
}
}
could just be:
// request headers
if (!requestAttrValues.noHeaders) {
Object.keys(headers)
.filter(hdr => headers.hasOwnProperty(hdr))
.forEach(hdr => safelySetHeaderValue(xhr, hdr, headers[hdr]));
}
Not even sure if that hasOwnProp check is needed, unless header keys are explicitly set to undef.
- recursivedoubts 2y agoyeah i prefer just plain ol' if statements, i find them easier to debug