@@ -475,8 +475,7 @@ Add a new component like this:
475
475
class EditItem < Hyperloop ::Component
476
476
param :todo
477
477
render do
478
- INPUT (defaultValue: params.todo.title, key: params.todo.object_id)
479
- # we will explain 'key: params.todo.object_id later'
478
+ INPUT (defaultValue: params.todo.title)
480
479
.on(:key_down ) do |evt |
481
480
next unless evt.key_code == 13
482
481
params.todo.update(title: evt.target.value)
@@ -551,7 +550,7 @@ class TodoItem < Hyperloop::Component
551
550
state editing: false
552
551
render(LI ) do
553
552
if state.editing
554
- EditItem (todo: params.todo, key: params.todo.object_id )
553
+ EditItem (todo: params.todo)
555
554
.on(:save , :cancel ) { mutate.editing false }
556
555
else
557
556
INPUT (type: :checkbox , checked: params.todo.completed)
@@ -631,15 +630,15 @@ Changing the value of the key, will inform React that we are refering to a new T
631
630
We are just going to steal the style sheet from the benchmark Todo app, and add it to our assets.
632
631
633
632
** Go grab the file in this repo here:** https://github.com/ruby-hyperloop/todo-tutorial/blob/master/app/assets/stylesheets/todo.css
634
- and copy it to a new file called ` todo.css ` in the ` app/assets/stylesheets/ `
633
+ and copy it to a new file called ` todo.css ` in the ` app/assets/stylesheets/ ` directory.
635
634
636
- You will have to refresh the page after changing the style sheet
635
+ You will have to refresh the page after changing the style sheet.
637
636
638
637
Now its a matter of updating the css classes which are passed to components via the ` class ` parameter.
639
638
640
639
Let's start with the ` App ` component. With styling it will look like this:
641
640
``` ruby
642
- # app/hyperloop/components/show .rb
641
+ # app/hyperloop/components/app .rb
643
642
class App < Hyperloop ::Router
644
643
history :browser
645
644
route do
@@ -701,10 +700,7 @@ class EditItem < Hyperloop::Component
701
700
class : params.className ,
702
701
defaultValue: params.todo.title,
703
702
key: params.todo.object_id
704
- ).on(:change ) do |evt |
705
- params.todo.title = evt.target.value
706
- end
707
- .on(:key_down ) do |evt |
703
+ ).on(:key_down ) do |evt |
708
704
next unless evt.key_code == 13
709
705
params.todo.save
710
706
params.on_save
@@ -865,7 +861,7 @@ class TodoItem < Hyperloop::Component
865
861
state editing: false
866
862
render(LI , class : ' todo-item' ) do
867
863
if state.editing
868
- EditItem (todo: params.todo, className : :edit )
864
+ EditItem (todo: params.todo, class : :edit)
869
865
.on(:save , :cancel ) { mutate.editing false }
870
866
else
871
867
INPUT (type: :checkbox , class : :toggle, checked: params.todo.completed)
@@ -881,10 +877,10 @@ end
881
877
# app/hyperloop/components/edit_item.rb
882
878
class EditItem < Hyperloop ::Component
883
879
param :todo
884
- param :on_save , type: Proc # add
885
- param :on_cancel , type: Proc # add
880
+ param :on_save , type: Proc
881
+ param :on_cancel , type: Proc
886
882
param :className
887
- after_mount { Element [dom_node].focus } # add
883
+ after_mount { Element [dom_node].focus }
888
884
889
885
render do
890
886
INPUT (
@@ -895,7 +891,7 @@ class EditItem < Hyperloop::Component
895
891
).on(:key_down ) do |evt |
896
892
next unless evt.key_code == 13
897
893
params.todo.update(title: evt.target.value)
898
- params.on_save # add
894
+ params.on_save
899
895
end
900
896
.on(:blur ) { params.on_cancel }
901
897
end
0 commit comments