>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.