Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shouldSwap field to htmx:sseBeforeMessage event detail #26

Closed
vlence opened this issue May 22, 2024 · 1 comment
Closed

Add shouldSwap field to htmx:sseBeforeMessage event detail #26

vlence opened this issue May 22, 2024 · 1 comment

Comments

@vlence
Copy link
Contributor

vlence commented May 22, 2024

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
Copy link
Contributor Author

vlence commented May 29, 2024

Closing because I just found out we can call preventDefault() on the htmx:sseBeforeMessage event to stop the swap.

@vlence vlence closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant