Skip to content

Instantly share code, notes, and snippets.

@catmando
Created February 26, 2021 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catmando/47150490125ccdfed5b4c2d9117d2a2e to your computer and use it in GitHub Desktop.
Save catmando/47150490125ccdfed5b4c2d9117d2a2e to your computer and use it in GitHub Desktop.
hyperstack vs hotwire - show_tweet.rb
class ShowTweet < HyperComponent
param :tweet
render(DIV, class: "card card-body") do
DIV { tweet.body } unless @editing
DIV(class: "mt-2") do
BUTTON { "Likes (#{tweet.likes_count})" }.on(:click) { tweet.increment!(:likes_count) }
BUTTON { "Retweets (#{tweet.retweets_count})" }.on(:click) { tweet.increment!(:retweets_count) }
if @editing
EditTweet(tweet: tweet, cancel_button: true)
.on(:saved, :canceled) { mutate @editing = false }
else
BUTTON { 'Edit Tweet' }.on(:click) { mutate @editing = true }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment