Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit a58c98e

Browse files
authored
more fixups
1 parent 31b4c4a commit a58c98e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ Add a new component like this:
475475
class EditItem < Hyperloop::Component
476476
param :todo
477477
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)
480479
.on(:key_down) do |evt|
481480
next unless evt.key_code == 13
482481
params.todo.update(title: evt.target.value)
@@ -551,7 +550,7 @@ class TodoItem < Hyperloop::Component
551550
state editing: false
552551
render(LI) do
553552
if state.editing
554-
EditItem(todo: params.todo, key: params.todo.object_id)
553+
EditItem(todo: params.todo)
555554
.on(:save, :cancel) { mutate.editing false }
556555
else
557556
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
631630
We are just going to steal the style sheet from the benchmark Todo app, and add it to our assets.
632631

633632
**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.
635634

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.
637636

638637
Now its a matter of updating the css classes which are passed to components via the `class` parameter.
639638

640639
Let's start with the `App` component. With styling it will look like this:
641640
```ruby
642-
# app/hyperloop/components/show.rb
641+
# app/hyperloop/components/app.rb
643642
class App < Hyperloop::Router
644643
history :browser
645644
route do
@@ -701,10 +700,7 @@ class EditItem < Hyperloop::Component
701700
class: params.className,
702701
defaultValue: params.todo.title,
703702
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|
708704
next unless evt.key_code == 13
709705
params.todo.save
710706
params.on_save
@@ -865,7 +861,7 @@ class TodoItem < Hyperloop::Component
865861
state editing: false
866862
render(LI, class: 'todo-item') do
867863
if state.editing
868-
EditItem(todo: params.todo, className: :edit)
864+
EditItem(todo: params.todo, class: :edit)
869865
.on(:save, :cancel) { mutate.editing false }
870866
else
871867
INPUT(type: :checkbox, class: :toggle, checked: params.todo.completed)
@@ -881,10 +877,10 @@ end
881877
# app/hyperloop/components/edit_item.rb
882878
class EditItem < Hyperloop::Component
883879
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
886882
param :className
887-
after_mount { Element[dom_node].focus } # add
883+
after_mount { Element[dom_node].focus }
888884

889885
render do
890886
INPUT(
@@ -895,7 +891,7 @@ class EditItem < Hyperloop::Component
895891
).on(:key_down) do |evt|
896892
next unless evt.key_code == 13
897893
params.todo.update(title: evt.target.value)
898-
params.on_save # add
894+
params.on_save
899895
end
900896
.on(:blur) { params.on_cancel }
901897
end

0 commit comments

Comments
 (0)