top | item 26554746

(no title)

023984398 | 5 years ago

This is cool but its not using hotwire (turbo frames / turbo streams)

discuss

order

strzibny|5 years ago

It does! Stimulus 2 is Hotwire too[0].

Turbo seemed more connected with existing models, and so I chose a Stimulus controller instead. But maybe I just don't know Turbo as much yet.

[0] https://stimulus.hotwire.dev/

edwinvlieg|5 years ago

The whole idea of Hotwire is to prevent `Rails.ajax` calls. You can easily accomplish this with less code:

1. Replace the `output` target with a Turbo frame. 2. Add a value to the `data-controller` div with a `preview-url`: https://stimulus.hotwire.dev/reference/values 3. Change the `Rails.ajax` call with `let url = URL.new(this.previewUrlValue); url.searchParams.append('body', this.tweetTarget.value; this.outputTarget.src = url.toString();` 4. Change the `preview` action to render HTML with the same frame.

Now you have an automatic refreshing frame with less code.

023984398|5 years ago

I mean technically they are installed but the example is still using UJS and not the functionality provided by the hotwire libs.

oh_boy|5 years ago

At least in the non-rails environment, Turbo and Stimulus are two separate libraries and have to be included individually.