4 ms·
The post is well written but I don't see the point in this when you can achieve the same in 145 bytes of JS (vs 80kb of stimulus) and avoid a trip to the server
by kaleidawave 6y ago
The post is well written but I don't see the point in this when you can achieve the same in 145 bytes of JS (vs 80kb of stimulus) and avoid a trip to the server:
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?
- strzibny 6y agoYou are right, but the point is that you can do a lot of transformations in Ruby. The demo doesn't do it justice, you can be converting the content to Markdown for example. As for the Stimulus part, the idea is to use Stimulus for everything interactive, so those extra 80kb is for the whole application.
- wavesplash 6y agoThe author just used Stimulus, not Hotwire - if you add Turbo (the main part of Hotwire) you can remove all the ajax calls. See thread below: https://news.ycombinator.com/item?id=26555842 https://news.ycombinator.com/item?id=26555842 )
- strzibny 6y agoYes, it doesn't use Turbo, but Stimulus is part of Hotwire as well. And actually I do just send a complete HTML over the wire (even if just with AJAX).
- wavesplash 6y agoHey, thanks for the article. The goal of Hotwire is to remove Ajax calls and minimize Javascript client coding as much as possible. That starts with Turbo as the foundation and then Stimulus is the next layer up. There's nothing wrong with doing what you did w/ Stimulus, but calling it Hotwire creates unnecessary confusion for those new to Rails+Hotwire. That confusion is what I'm addressing in the grandparent comment.
- strzibny 6y agoI included a second example with Turbo Frame, but I am keeping Stimulus since it's what the article is about (and it's in the title). Maybe you can do without it but you have to use some hidden forms or something. I believe Stimulus makes it "clean." Btw Turbo Stream is kind of cool, but in this particular case, do you think its' really better?