htmx-extensions icon indicating copy to clipboard operation
htmx-extensions copied to clipboard

Add `shouldSwap` field to `htmx:sseBeforeMessage` event detail

Open vlence opened this issue 1 year ago • 0 comments

I believe that having a shouldSwap boolean field on the htmx:sseBeforeMessage event detail would make this event more useful. There are situations, I have personally come across them, where we don't want to swap in the SSE message and being able to opt out of that would be very useful.

I can make a PR for this. In my own project I have found that it can be achieved very easily.

// swap the response into the DOM and trigger a notification
event.shouldSwap = true
if (!api.triggerEvent(elt, 'htmx:sseBeforeMessage', event)) {
  return
}

if (event.shouldSwap) {
  swap(elt, event.data)
  api.triggerEvent(elt, 'htmx:sseMessage', event)
}

vlence avatar May 22 '24 06:05 vlence