khalidabuhakmeh / htmx-aspnetcore

HTMX & ASP.NET Core Samples
MIT License
136 stars 36 forks source link

Cart update does not trigger items quantities to refresh in the products view #3

Open jch-neos opened 6 months ago

jch-neos commented 6 months ago

When testing out the demo shop, I tried updating the cart directly from the cart items view and I saw that the items quantities do not update. I'm not sure what the idiomatic HTMX solution would be, should the whole page be triggered ?

khalidabuhakmeh commented 6 months ago

Hi @jch-neos, you should be able to use the hx-trigger with a custom event. That said, I have found using out-of-band updates to also be a good way to update chrome elements (things in the header).

https://htmx.org/attributes/hx-trigger/

jcheritat commented 6 months ago

I see how you implemented it and how your last commit corrects the issue (I was getting ready to make a pull request for that 😆)

However I still have a feeling of a scaling issue since you have to include every possible change in you update. Even using composition like you did it's seems complexe to manage all possible updates linked to an event.

khalidabuhakmeh commented 6 months ago

@jcheritat it's true, it depends on what you're attempting. If you can have some UI lag then invoking an hx-trigger event after the response comes back would be easier to logic about. All about trade-offs and compromises. :)

I really should think about creating an HTMX.NET online user-group where we can talk about this stuff. 😅

khalidabuhakmeh commented 6 months ago

👋 Hi folks. I wrote a sample thanks to a blog post from Htmx.Net contributor showing how to use Hx-Trigger to listen and react to global events coming from the server.

This is a nice way to scale up your UI if you don't want to use out-of-band swaps. Try it out!

https://github.com/khalidabuhakmeh/HxTriggerSample