Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 23 additions & 39 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,7 @@ var htmx = (function() {
* @returns {T1 & T2}
*/
function mergeObjects(obj1, obj2) {
for (const key in obj2) {
if (obj2.hasOwnProperty(key)) {
// @ts-ignore tsc doesn't seem to properly handle types merging
obj1[key] = obj2[key]
}
}
// @ts-ignore tsc doesn't seem to properly handle types merging
return obj1
return Object.assign({}, obj1, obj2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caniuse says this goes back to 2015, basically: https://caniuse.com/mdn-javascript_builtins_object_assign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK, do we have a policy on minimum supported browser version?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an official one, just noting it to say that I think it's okay!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is fully supported as this is ES6/ES2015 and we already have many features used from this version when we did v2.0. We should probably decide on a better baseline we want to rule in or out like ES2020 or ES2018 as i've seen ES2016 things like array.includes is already in the code base

}

/**
Expand Down Expand Up @@ -2064,18 +2057,16 @@ var htmx = (function() {
function handleTriggerHeader(xhr, header, elt) {
const triggerBody = xhr.getResponseHeader(header)
if (triggerBody.indexOf('{') === 0) {
const triggers = parseJSON(triggerBody)
for (const eventName in triggers) {
if (triggers.hasOwnProperty(eventName)) {
let detail = triggers[eventName]
if (isRawObject(detail)) {
// @ts-ignore
elt = detail.target !== undefined ? detail.target : elt
} else {
detail = { value: detail }
}
triggerEvent(elt, eventName, detail)
const triggers = parseJSON(triggerBody) || {}
for (const eventName of Object.keys(triggers)) {
let detail = triggers[eventName]
if (isRawObject(detail)) {
// @ts-ignore
elt = detail.target !== undefined ? detail.target : elt
} else {
detail = { value: detail }
}
triggerEvent(elt, eventName, detail)
}
} else {
const eventNames = triggerBody.split(',')
Expand Down Expand Up @@ -2795,7 +2786,7 @@ var htmx = (function() {
const boostedSelector = ', [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]'

const extensionSelectors = []
for (const e in extensions) {
for (const e of Object.keys(extensions)) {
const extension = extensions[e]
if (extension.getSelectors) {
var selectors = extension.getSelectors()
Expand Down Expand Up @@ -3942,11 +3933,9 @@ var htmx = (function() {
} else {
varsValues = parseJSON(str)
}
for (const key in varsValues) {
if (varsValues.hasOwnProperty(key)) {
if (values[key] == null) {
values[key] = varsValues[key]
}
for (const key of Object.keys(varsValues)) {
if (values[key] == null) {
values[key] = varsValues[key]
}
}
}
Expand Down Expand Up @@ -4120,15 +4109,13 @@ var htmx = (function() {
function formDataFromObject(obj) {
if (obj instanceof FormData) return obj
const formData = new FormData()
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] && typeof obj[key].forEach === 'function') {
obj[key].forEach(function(v) { formData.append(key, v) })
} else if (typeof obj[key] === 'object' && !(obj[key] instanceof Blob)) {
formData.append(key, JSON.stringify(obj[key]))
} else {
formData.append(key, obj[key])
}
for (const key of Object.keys(obj)) {
if (obj[key] && typeof obj[key].forEach === 'function') {
obj[key].forEach(function(v) { formData.append(key, v) })
} else if (typeof obj[key] === 'object' && !(obj[key] instanceof Blob)) {
formData.append(key, JSON.stringify(obj[key]))
} else {
formData.append(key, obj[key])
}
}
return formData
Expand Down Expand Up @@ -4535,11 +4522,8 @@ var htmx = (function() {
if (requestAttrValues.noHeaders) {
// ignore all headers
} else {
for (const header in headers) {
if (headers.hasOwnProperty(header)) {
const headerValue = headers[header]
safelySetHeaderValue(xhr, header, headerValue)
}
for (const header of Object.keys(headers)) {
safelySetHeaderValue(xhr, header, headers[header])
}
}

Expand Down