Comments (5)
Yeah, ultimately every UX at least starts at the server. And mostly almost immediately need to go back to do something there again. Which is why Hotwire/LiveView/htmx/etc work so well. It's super awesome, and incredibly powerful. Not doubting that at all, been using it for quite awhile now and it's really revolutionized some of the things I work on. Just sort of ran into a weird.. middle scenario, that I'm not quite sure how to handle with Hotwire?
I'll shed a bit of context on what even got me thinking about this. But basically, it's just a complex form. Data isn't yet persisted until saved, but there is dependent state on that data that is yet to be persisted.
The product I work on is a CRM software. Currently, our users have their clients contact info in our system, and those clients can be grouped into families. But for various legacy reasons, things are a bit messy. A given family might have all the right contact info in there, but it's spread out across all the people. Maybe mom's phone number is on all 3 kids, and mom doesn't exist in the system, things like that.
So, we're providing a way to remedy that. Effectively, this form let's you reassign contact info, add new contact info, and determine who the primary point of contact is for that family.
Originally I built it with Turbo, and my solution was to use multiple submit buttons to handle it, with varying formactions. For example, there's a button to add a phone number, it streams down the new fields and uses the data from the form to keep clients state correct. Like, who can be assigned a phone number, since we only allow one per person. Which felt.. weird to me? Could totally be the completely wrong approach.
The Turbo solution worked. It just felt.. kinda odd? Ends up being a lot of extra requests for a bunch of state that exists only on the client until the point of submission. Ultimately it felt like bending Turbo to make it work, not something that Turbo was intended to be used for.
The key part is, most of it works super nicely with Turbo. But at that boundary where there's unpersisted dependent state on the client, I've got a wee bit of CSR like shown above. Just to kinda tie the two boundaries together. Which is what prompted this, it felt odd to me that there wasn't a solution built in.
Ultimately, I could be totally missing the mark here still. Please let me know if I am! Thanks a ton.
TLDR: Complex forms that have dependent state on unpersisted data is the heart of it.
from stimulus.
Okay so, after having voiced those thoughts, I think I've actually talked myself through everything.
Ultimately, I think the solution is just.. don't pass that state back to the server. Any changes that need to take place can just happen on the client after the server renders the markup.
That seems like a much happier path, and I think should suffice?
from stimulus.
Wouldn't you want the selected items in a shopping cart to be held on the server?
- So that the user still has them after they close the window.
- In order to do data analysis of what people are shopping for.
- So that the user can switch devices (assuming they have an account) and maintain their cart.
...other reasons...
I suppose you could accomplish #1 with cookies alone but that seems messy.
from stimulus.
@tpaulshippy ultimately with a cart yeah you probably would, not a great example. But, that's beside the point.
There are still ultimately UXs that exist that don't require hitting the server. What is the suggested way to handle those with Hotwire?
Maybe that's a flawed question in itself?
from stimulus.
It's a good question. But it does sorta go to the heart of the Hotwire philosophy.
There are still ultimately UXs that exist that don't require hitting the server.
Are there? Doesn't every UX ultimately come from the server at some point? You said "hitting the server" which implies a UX that has already been loaded to the client. Sure, and I think anyone would admit that Hotwire is not as good at building UX that is 100% client side (many kinds of games, for example). But you might be surprised at how powerful a UX can be built by delivering HTML from the server as the primary means of showing interfaces. That is part of the argument the makers of libraries and frameworks like Hotwire, Phoenix Liveview, and htmx are making.
If you have another specific scenario in mind I'd love to hear more about it.
from stimulus.
Related Issues (20)
- Callback Ordering Inconsistency in Documentation HOT 1
- disconnect() not called if outlet is accessed in connect() HOT 6
- Expired certificate on a CDN HOT 1
- Wrong params passed to action when multiple actions from multiple controllers HOT 4
- Progress bar keeps on loading forever
- Question about Stimulus' life cycle HOT 2
- Conflicting Fetch between stimulus and Hotwire HOT 4
- Value declared with a {type: String} but no default value behave like they have a default value
- This.element is showing a previous (cached?) version of the DOM element HOT 1
- Turbo Drive: Stimulus doesn't disconnect/connect after redirection to same URL HOT 3
- Support multiple keystroke binds for KeyboardEvent Filter
- Stimulus controllers imported twice, Initialize and clickEvents firing twice HOT 5
- Outlets do not disconnect when removed via morph
- work with BigInt HOT 2
- classList.remove() doesn't do anything on target HOT 4
- [v3.2.2] Input type "date" and "datetime-local" do not display initial value HOT 3
- Load failed errors when sending fetch requests in Safari on iOS devices. HOT 1
- Value changed fires without reflecting a change HOT 2
- Outlets property name in nested controller path
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stimulus.