FEATURE: Swap HTML on Server Sent Events (take 5) #194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the new SSE syntax proposed by @1cg, and fixes my previous PR that was built upon the wrong base branch I'll briefly summarize his spec here:
Swapping on Named Events
This PR adds a new
swap on
syntax to the hx-sse attribue that can be used to swap content into the DOM for any named SSE event.The
swap on
indicates that this element wants to listen forchatter
messages and swap the body when they occur.The
hx-swap
attribute can then be used to determine exactly how the swap is done, as with normal swaps.Data-only Messages
In the case of a data-only message, the message type is
message
according to the SSE spec. Thus, the formswap on message
should work the same as the named event implementation.Declaring and Using An SSE Endpoint On The Same Element
This PR supports both connecting and listening for an event (or events) in the same
hx-sse
declaration, byallowing comma separated values:
Leave Triggers In Place
This PR does not change the way that SSE can be used to trigger additional events in HTMX. So the following, original code still works:
Links