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

allow notifications to be added as another event #13

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

MarhyCZ
Copy link
Contributor

@MarhyCZ MarhyCZ commented Mar 15, 2024

Hi,
I hit a usecase where I wanted to send in one response a Success notification to a user and also second event so that HTMX can fetch new data.

I moved logic composing notify object from the handler notifyObject into a new method addNotifyObject in Trigger struct. This struct also now exposes public methods like AddSuccess, AddInfo, AddError etc..

So that composing triggers like below will be possible:

trigger := htmx.NewTrigger()
trigger.AddEvent("fl:record:updated")
trigger.AddSuccess("Transcription updated")
hx.TriggerWithObject(trigger)

Also I added tests for a good measure. :-)

With this, composing triggers like below will be possible

trigger := htmx.NewTrigger()
trigger.AddEvent("fl:record:updated")
trigger.AddSuccess("Transcription updated")
hx.TriggerWithObject(trigger)
@donseba
Copy link
Owner

donseba commented Mar 15, 2024

Hi! Thanks for the contribution!

I will give it a look tomorrow and get back to you.

I assume this doesn't break current flows?

@MarhyCZ
Copy link
Contributor Author

MarhyCZ commented Mar 15, 2024

Hi! Thanks for such a quick notice.

It should not break anything. Standard notification handlers like TriggerInfo, TriggerCustom, TriggerError,.. still work. ☺️

Copy link
Owner

@donseba donseba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution! If you have more ideas please let me know !

@donseba donseba merged commit f6327e3 into donseba:main Mar 16, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants