|
113 | 113 | await hydroRequest(el, url, { eventData: { name: wireEventData.name, data: eventData.data, subject: eventData.subject } }, 'event', wireEventData, operationId); |
114 | 114 | } |
115 | 115 |
|
116 | | - async function hydroBind(el) { |
| 116 | + async function hydroBind(el, debounce) { |
117 | 117 | if (!isElementDirty(el)) { |
118 | 118 | return; |
119 | 119 | } |
|
165 | 165 | clearTimeout(binding[component.id].timeout); |
166 | 166 | } |
167 | 167 |
|
168 | | - return await new Promise(resolve => { |
| 168 | + |
| 169 | + binding[component.id].promise = new Promise(resolve => { |
169 | 170 | binding[component.id].timeout = setTimeout(async () => { |
170 | 171 | const requestFormData = binding[component.id].formData; |
171 | 172 | // binding[url].formData = new FormData(); |
|
176 | 177 | delete dirty[propertyName]; |
177 | 178 | } |
178 | 179 | resolve(); |
179 | | - }, 10); |
| 180 | + }, Math.max(debounce, 10)); |
180 | 181 | }); |
| 182 | + |
| 183 | + return binding[component.id].promise; |
181 | 184 | } |
182 | 185 |
|
183 | 186 | async function hydroAction(el, component, action) { |
|
234 | 237 | operationStatus[operationId]++; |
235 | 238 | } |
236 | 239 |
|
| 240 | + if (type === 'action') { |
| 241 | + if (binding[componentId]?.promise) { |
| 242 | + await binding[componentId].promise; |
| 243 | + } |
| 244 | + } |
| 245 | + |
237 | 246 | await enqueueHydroPromise(componentId, async () => { |
238 | 247 | try { |
239 | 248 | let headers = { |
|
327 | 336 | } |
328 | 337 |
|
329 | 338 | if (from.getAttribute && from.getAttribute("hydro-operation-id")) { |
330 | | - if (type === 'bind' && operationId !== from.getAttribute("hydro-operation-id")) { |
| 339 | + if (type === 'bind' && operationId !== from.getAttribute("hydro-operation-id") && from.getAttribute("hydro") === null) { |
331 | 340 | skip(); |
332 | 341 | counter++; |
333 | 342 | return; |
|
423 | 432 | operationTrigger.forEach(trigger => { |
424 | 433 | trigger.disabled = false; |
425 | 434 | trigger.classList.remove('hydro-request'); |
| 435 | + trigger.removeAttribute('hydro-operation-id'); |
426 | 436 | }) |
427 | 437 | } |
428 | 438 | } |
@@ -490,10 +500,6 @@ document.addEventListener('alpine:init', () => { |
490 | 500 |
|
491 | 501 | const eventName = el.getAttribute('hydro-event') || 'click'; |
492 | 502 |
|
493 | | - if (!component.element.parentElement) { |
494 | | - debugger; |
495 | | - } |
496 | | - |
497 | 503 | const parentComponent = window.Hydro.findComponent(component.element.parentElement); |
498 | 504 |
|
499 | 505 | const trigger = JSON.parse(expression); |
@@ -537,19 +543,13 @@ document.addEventListener('alpine:init', () => { |
537 | 543 |
|
538 | 544 | const debounce = parseInt(((modifiers[0] === 'debounce' && (modifiers[1] || '250ms')) || '0ms').replace('ms', '')); |
539 | 545 |
|
540 | | - let timeout = 0; |
541 | | - |
542 | 546 | const eventHandler = async (event) => { |
543 | 547 | if (event === 'submit' || event === 'click') { |
544 | 548 | event.preventDefault(); |
545 | 549 | } |
546 | 550 |
|
547 | | - clearTimeout(timeout); |
548 | | - |
549 | 551 | const target = event.currentTarget; |
550 | | - timeout = setTimeout(async () => { |
551 | | - await window.Hydro.hydroBind(target); |
552 | | - }, debounce); |
| 552 | + await window.Hydro.hydroBind(target, debounce); |
553 | 553 | }; |
554 | 554 |
|
555 | 555 | el.addEventListener(event, eventHandler); |
|
0 commit comments