-
Notifications
You must be signed in to change notification settings - Fork 62
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 trigger 'htmx:sseClose' to sse close event #31
Conversation
✅ Deploy Preview for htmx-extensions canceled.
|
Hey, while I like the idea, it seems you aren't firing this event in all cases where a source might be closed, was it intended? htmx-extensions/src/sse/sse.js Lines 47 to 49 in 8845604
htmx-extensions/src/sse/sse.js Lines 239 to 243 in 8845604
Also, do you think that, on error, a Also, to accept this PR it'd be good to add the following :
|
Hi, thank you for the review and recommendations! I understand your concerns about not firing the Initially, I intended to trigger the event only when a closing message is received, not when the connection is closed due to the removal of the element containing Regarding your suggestion to fire the same event for all closing connections, I'm open to implementing |
Oh I see, makes sense! I think a parameter could make more sense? An enum-like value in the event's details that lets the user know, if it matters to them, what was the reason of this sse close. So that if someone just wants to bind some logic upon a sse connection closing, they don't have to bind 3 different events, and if they need to differentiate the scenarios, they may simply use if/else or a switch statement |
Hi @Telroshan , I have added test cases and implemented the close types in the event details. Thank you for the recommendation. Users can access the sseClose details as follow: document.body.addEventListener('htmx:sseClose', function (e) {
const reason = e.detail.type
switch(reason) {
case "nodeMissing":
// Parent node is missing and therefore connection was closed
...
case "nodeReplaced":
// Parent node replacement caused closing of connection
...
case "message":
// connection was closed due to reception of message sse-close
...
}
}) |
Looks good @sondalex, thanks! |
Sure @Telroshan , I have just fixed it. |
Perfect, thanks! |
This PR adds a new trigger,
"htmx:sseClose"
, which is emitted when an SSE closing message is received.