-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
Make params argument of trigger_client_event() optional #263
Make params argument of trigger_client_event() optional #263
Conversation
Good stuff, the empty trailing payload has been triggering me for a while |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite complicated to try supporting the non-JSON form of the header. It looks like we could just send HX-Trigger: {"event": null}
or {"event": {}}
if params aren't provided, which is a much smaller change?
Would certainly simplify things. Supporting the non-JSON form is probably an unnecessary micro-optimisation, though one advantage of it is that it's slightly less cumbersome to assert for in tests. We'll want to use |
Tests will just assert for the raw string
Okay, right. Can you do it then? Please also rebase, and add changelog note and docs 😇 |
Yep, will have some time to make these changes a bit later today |
692e8f8
to
d051a8e
Compare
d051a8e
to
fe64ddd
Compare
Well, this has ended up being a much smaller diff. I guess it saves me from typing four extra characters every time I call There wasn't an example in the changelog for how you like to list consecutive PRs from the one contributor, so I just included the same "thanks to..." message a second time. |
Thank you very much!
Yup this is good. |
This PR adds support for triggering a client event with no params without having to call the
trigger_client_event
with aparams
argument. It also adds support for using string rather than JSON value for theHX-Trigger*
when there is only a single event with no params (see https://htmx.org/headers/hx-trigger/).I chose to set the default value of promoted events to
{}
rather thanNone
(or something else), as this mirrors how HTMX itself handles events with no params (it sets the details to an empty object; see https://github.com/bigskysoftware/htmx/blob/60acaacc416812e85245f8e00d1e8bc4954d1d83/src/htmx.js#L992-L1008)I realise that the docs will also need to be updated - I'm happy to do this as well, but just wanted to check that this would actually be accepted first :)