What is the rule of thumb for deciding whether to use turbo_frames or stimulus?

I have repeatedly been faced with the question of what strategy to use for certain features. Turbo is awesome and had made this a difficult question because many things that normally would normally require javascript can be done using Turbo.

For example, if I want to toggle an edit mode, which reveals a bunch of buttons throughout my webpage for editing content, should I use a stimulus controller to unhide them all? Or just re-render the page using turbo frames?

Is there a rule of thumb I should follow for this kind of thing?

Thanks!

Hi!

I think that always depends on your case and what rules are you defining to use in your project. In my case we try to avoid JS if we can use turbo and delegate work to stimulus just when the work can’t be accomplished with it or if it’s more complicated.

So in my case, I always think:

  • Can I accomplish this behavior with turbo? Yes/No
  • How complicated it is to achieve the result with it?

Hope it works.

Cheers!

Hmm… in my case it’s pretty easy to iterate over elements and toggle a class to hide/unhide them in JS. It would be much more verbose to wrap all those elements in conditions in my views, so I think that complication makes Stimulus the better choice.

Thanks for your advice!