You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -755,7 +755,7 @@ Wow! We just had to copy and paste a JavaScript snippet once in order to integra
755
755
756
756
We will take a short break before adding the next cool reactivity feature and refactor a little bit! Matestack encourages you to create a readable and maintainable UI implemetation. Therefore we will move some complexity from the current index page to a self contained Matestack component!
757
757
758
-
## Create a Matestack component
758
+
## Create a Matestack Component
759
759
760
760
*[x] Create a components folder within the matestack folder
# async rerender_on: "cable__liked_post_#{post.id}", id: "post-#{post.id}" do
830
+
# div class: "mb-3 p-3 rounded shadow-sm" do
831
+
# heading size: 5 do
832
+
# plain post.username
833
+
# small text: post.created_at.strftime("%d.%m.%Y %H:%M")
834
+
# end
835
+
# paragraph text: post.body, class: "mb-5"
836
+
# action path: like_post_path(post), method: :put do
837
+
# button class: "btn btn-light" do
838
+
# plain "Like (#{post.likes_count})"
839
+
# end
840
+
# end
841
+
# end
842
+
# end
843
+
# end
844
+
845
+
end
801
846
```
802
847
803
-
*[x] Register the new component
848
+
**Test the current state**
849
+
850
+
*[x] Navigate to `localhost:3000/posts`
851
+
852
+
Everything should be the same! We just refactored some code in order to better manage complexity.
804
853
805
-
`app/matestack/components/registry.rb`
854
+
855
+
## Component Registry
856
+
857
+
Components can be invoked as we have done above (`Components::Post.(post: post)`). But sometimes the namespace can get a little long and in the interest of keeping our code beautiful, we can register our components so we can call them like:
0 commit comments