by nilsandrey on 3/23/21, 1:02 PM with 49 comments
by strzibny on 3/23/21, 7:47 PM
Of course there are even more ways how to do this kind of thing. Keep sharing!
by rolae on 3/23/21, 3:56 PM
I had to throw in some debouncing and special handling for hidden inputs, as changes to hidden inputs do not trigger a change event on the form.
In the end the markup was very simple and is very reusable (StimulusJS v1):
<div data-controller="iframe-preview" data-iframe-preview-url="<%= preview_path(@letter) %>">
<form data-target="iframe-preview.form">
<textarea name="body">My letter</textarea>
</form>
<iframe data-target="iframe-preview.iframe">
</div>
This is when StimulusJS becomes really nice, when you can compose behavior in your markup with some simple data attributes. I did not think at first that I would need this controller in other places, but a couple of weeks later, I actually needed it, and was able to reuse the controller without modification for another use case.by yuppiepuppie on 3/23/21, 2:29 PM
by Igor_Wiwi on 3/23/21, 2:30 PM
by 023984398 on 3/23/21, 1:32 PM
by stevebmark on 3/23/21, 8:20 PM
- Making everything go through a "controller" instead of well designed clients and APIs. Mixing rendering, redirection, ajax handling as well as page serving as well as business logic all into a "controller" is painful. ("Models" and the spaghetti design patterns they come with are even worse)
- PHP style templates that trigger database queries inline, making them difficult and eventually impossible to optimize
- Scattering view code across random places instead of writing view code with its corresponding view logic in the same file/component
- Wiring up functionality to templates by targeting selectors
- Manually setting innerHTML for dynamic functionality
- Dealing with rails "turbo" anything, which is not useful in a real world application, and dangerous (we've had production outages because of trying to use turbolinks)
- Not being able to customize behavior because you're locked into Rails design limitations
by shay_ker on 3/23/21, 6:02 PM
I'm a bit skeptical of Rails performance with the method the author details here, given that Ruby is much, much slower than Elixir.
I'm curious if even Elixir folks deploy Live Views in consumer-facing apps. But I can totally see it being used for admin interfaces or internal applications, for sure.
by lucidone on 3/23/21, 4:52 PM
by jack_riminton on 3/23/21, 2:28 PM
by kaleidawave on 3/23/21, 5:36 PM
document.querySelector("input").addEventListener("input", e => { document.querySelector("p").innerHTML = `<strong>${e.target.value}</strong>` });
Reusing the logic could be done if the server was node or through compiling the formatter to wasm. I struggle to see how Hotwire makes things simpler and has comparable speed to a SPA?