Skip to content

Commit 0c398b9

Browse files
committed
version bump
1 parent 5ce6189 commit 0c398b9

File tree

33 files changed

+262
-253
lines changed

33 files changed

+262
-253
lines changed

docs/tutorial/todo.md

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
fires
22
# TodoMVC Tutorial (Rails 5.2.x)
33

44
### Prerequisites
@@ -437,13 +437,11 @@ Lets change `App` to look like this:
437437
# app/hyperstack/components/app.rb
438438
class App < HyperComponent
439439
include Hyperstack::Router
440-
render do
441-
SECTION do
442-
Header()
443-
Route('/', exact: true) { Redirect('/all') }
444-
Route('/:scope', mounts: Index)
445-
Footer()
446-
end
440+
render(SECTION) do
441+
Header()
442+
Route('/', exact: true) { Redirect('/all') }
443+
Route('/:scope', mounts: Index)
444+
Footer()
447445
end
448446
end
449447
```
@@ -609,16 +607,17 @@ To summarize:
609607
+ User saves the Todo being edited: editing changes to `false`.
610608
+ User changes focus away (`blur`) from the Todo being edited: editing changes to `false`.
611609

612-
In order to accomplish this our `EditItem` component is going to communicate to its parent via two application defined events - `saved` and `cancel` .
610+
In order to accomplish this our `EditItem` component is going to communicate to its parent via two application defined events - `saved` and `cancel`.
611+
613612
Add the following 5 lines to the `EditItem` component like this:
614613

615614
```ruby
616615
# app/hyperstack/components/edit_item.rb
617616
class EditItem < HyperComponent
618617
param :todo
619-
triggers :saved # add
620-
triggers :cancel # add
621-
after_mount { DOM[dom_node].focus } # add
618+
fires :saved # add
619+
fires :cancel # add
620+
after_mount { jQ[dom_node].focus } # add
622621

623622
render do
624623
INPUT(defaultValue: @Todo.title)
@@ -630,17 +629,17 @@ class EditItem < HyperComponent
630629
end
631630
end
632631
```
633-
The first two new lines add our custom events.
632+
The first two new lines add our custom events which will be *fired* by the component.
634633

635634
The next new line uses one of several *Lifecycle Callbacks*. In this case we need to move the focus to the `EditItem` component after it is mounted.
636-
The `DOM` class is Hyperstack's jQuery wrapper, and `dom_node`
635+
The `jQ` method is Hyperstack's jQuery wrapper, and `dom_node`
637636
is the method that returns the actual dom node where this *instance* of the component is mounted.
638637
This is the `INPUT` html element as defined in the render method.
639638

640-
The `saved!` line will trigger the saved event in the parent component.
641-
Notice that the method to trigger a custom event is the name of the event followed by a bang (!).
639+
The `saved!` line will fire the saved event in the parent component.
640+
Notice that the method to fire a custom event is the name of the event followed by a bang (!).
642641

643-
Finally we add the `blur` event handler and trigger our `cancel` event.
642+
Finally we add the `blur` event handler and fire our `cancel` event.
644643

645644
Now we can update our `TodoItem` component to react to three events: `double_click`, `saved` and `cancel`.
646645

@@ -663,7 +662,7 @@ class TodoItem < HyperComponent
663662
end
664663
end
665664
```
666-
All states in Hyperstack are simply Ruby instance variables (ivars, variables with a leading @). Here we use the `@editing` ivar.
665+
All states in Hyperstack are simply Ruby instance variables (ivars for short which are variables with a leading @). Here we use the `@editing` ivar.
667666

668667
We have already used a lot of states that are built into the HyperModel and HyperRouter.
669668
The states of these components are built out collections of instance variables like `@editing`.
@@ -748,17 +747,15 @@ Let's start with the `App` component. With styling it will look like this:
748747
# app/hyperstack/components/app.rb
749748
class App < HyperComponent
750749
include Hyperstack::Router
751-
render do
752-
SECTION(class: 'todo-app') do # add class todo-app
753-
Header()
754-
Route('/', exact: true) { Redirect('/all') }
755-
Route('/:scope', mounts: Index)
756-
Footer()
757-
end
750+
render(SECTION, class: 'todo-app') do # add class todo-app
751+
Header()
752+
Route('/', exact: true) { Redirect('/all') }
753+
Route('/:scope', mounts: Index)
754+
Footer()
758755
end
759756
end
760757
```
761-
The `Footer` components needs have a `UL` added to hold the links nicely,
758+
The `Footer` component needs to have a `UL` added to hold the links nicely,
762759
and we can also use the `NavLinks` `active_class` param to highlight the link that is currently active:
763760

764761
```ruby
@@ -772,7 +769,7 @@ class Footer < HyperComponent
772769
LI { NavLink("/#{path}", active_class: :selected) { path.camelize } }
773770
end
774771
render(DIV, class: :footer) do # add class footer
775-
UL(class: :filters) do # wrap links in a UL element with class filers
772+
UL(class: :filters) do # wrap links in a UL element with class filters
776773
link_item(:all)
777774
link_item(:active)
778775
link_item(:completed)
@@ -796,17 +793,17 @@ class Index < HyperComponent
796793
end
797794
```
798795
For the EditItem component we want the parent to pass any html parameters such as `class` along to the INPUT tag.
799-
We do this by adding the special `others` param that will collect any extra params, we then pass it along in to the INPUT tag.
796+
We do this by adding the special `other` param that will collect any extra params, we then pass it along in to the INPUT tag.
800797
Hyperstack will take care of merging all the params together sensibly.
801798

802799
```ruby
803800
# app/hyperstack/components/edit_item.rb
804801
class EditItem < HyperComponent
805802
param :todo
806-
triggers :saved
807-
triggers :cancel
808-
others :etc # can be named anything you want
809-
after_mount { DOM[dom_node].focus }
803+
fires :saved
804+
fires :cancel
805+
other :etc # can be named anything you want
806+
after_mount { jQ[dom_node].focus }
810807
render do
811808
INPUT(@Etc, defaultValue: @Todo.title, key: @Todo)
812809
.on(:enter) do |evt|
@@ -864,12 +861,14 @@ This is just a span that we add before the link tags list in the `Footer` compon
864861
...
865862
render(DIV, class: :footer) do
866863
SPAN(class: 'todo-count') do
867-
"#{Todo.active.count} item#{'s' if Todo.active.count != 1} left"
864+
# pluralize returns the second param (item) properly
865+
# pluralized depending on the first param's value.
866+
"#{pluralize(Todo.active.count, 'item')} left"
868867
end
869868
UL(class: :filters) do
870869
...
871870
```
872-
+ **Add 'placeholder' Text To Edit Item**\
871+
+ **Add 'placeholder' Text To Edit Item**
873872
`EditItem` should display a meaningful placeholder hint if the title is blank:
874873

875874
```ruby
@@ -879,7 +878,7 @@ INPUT(@Etc, placeholder: 'What is left to do today?',
879878
.on(:enter) do |evt|
880879
...
881880
```
882-
+ **Don't Show the Footer If There are No Todos**\
881+
+ **Don't Show the Footer If There are No Todos**
883882
In the `App` component add a *guard* so that we won't show the Footer if there are no Todos:
884883

885884
```ruby
@@ -899,7 +898,7 @@ You have built a small but feature rich full stack Todo application in less than
899898
```text
900899
SLOC
901900
--------------
902-
App: 11
901+
App: 9
903902
Header: 8
904903
Index: 10
905904
TodoItem: 16
@@ -908,7 +907,7 @@ Footer: 16
908907
Todo Model: 4
909908
Rails Route: 4
910909
--------------
911-
Total: 85
910+
Total: 83
912911
```
913912

914913
The complete application is shown here:
@@ -917,13 +916,11 @@ The complete application is shown here:
917916
# app/hyperstack/components/app.rb
918917
class App < HyperComponent
919918
include Hyperstack::Router
920-
render do
921-
SECTION(class: 'todo-app') do
922-
Header()
923-
Route('/', exact: true) { Redirect('/all') }
924-
Route('/:scope', mounts: Index)
925-
Footer() unless Todo.count.zero?
926-
end
919+
render(SECTION, class: 'todo-app') do
920+
Header()
921+
Route('/', exact: true) { Redirect('/all') }
922+
Route('/:scope', mounts: Index)
923+
Footer() unless Todo.count.zero?
927924
end
928925
end
929926

@@ -956,9 +953,7 @@ class Footer < HyperComponent
956953
LI { NavLink("/#{path}", active_class: :selected) { path.camelize } }
957954
end
958955
render(DIV, class: :footer) do
959-
SPAN(class: 'todo-count') do
960-
"#{Todo.active.count} item#{'s' if Todo.active.count != 1} left"
961-
end
956+
SPAN(class: 'todo-count') { "#{pluralize(Todo.active.count, 'item')} left" }
962957
UL(class: :filters) do
963958
link_item(:all)
964959
link_item(:active)
@@ -987,11 +982,11 @@ end
987982

988983
# app/hyperstack/components/edit_item.rb
989984
class EditItem < HyperComponent
990-
param :todo
991-
triggers :save
992-
triggers :cancel
993-
others :etc
994-
after_mount { DOM[dom_node].focus }
985+
param :todo
986+
fires :save
987+
fires :cancel
988+
other :etc
989+
after_mount { jQ[dom_node].focus }
995990
render do
996991
INPUT(@Etc, placeholder: 'What is left to do today?',
997992
defaultValue: @Todo.title, key: @Todo)

ruby/examples/misc/stock-tickers/Gemfile.lock

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
11
PATH
22
remote: ../../../hyper-component
33
specs:
4-
hyper-component (1.0.alpha1.1)
5-
hyper-state (= 1.0.alpha1.1)
6-
hyperstack-config (= 1.0.alpha1.1)
7-
libv8 (~> 6.3.0)
8-
mini_racer (~> 0.1.15)
4+
hyper-component (1.0.alpha1.3)
5+
hyper-state (= 1.0.alpha1.3)
6+
hyperstack-config (= 1.0.alpha1.3)
7+
libv8 (~> 6.7.0)
8+
mini_racer (~> 0.2.4)
99
opal (>= 0.11.0, < 0.12.0)
1010
opal-activesupport (~> 0.3.1)
1111
react-rails (>= 2.4.0, < 2.5.0)
1212

1313
PATH
1414
remote: ../../../hyper-spec
1515
specs:
16-
hyper-spec (1.0.alpha1.1)
16+
hyper-spec (1.0.alpha1.3)
1717
capybara
1818
chromedriver-helper (= 1.2.0)
19-
libv8 (~> 6.3.0)
19+
libv8
2020
method_source
21-
mini_racer (~> 0.1.15)
21+
mini_racer (~> 0.2.4)
2222
opal (>= 0.11.0, < 0.12.0)
2323
parser (>= 2.3.3.1)
2424
pry
2525
rspec-rails
2626
selenium-webdriver
2727
timecop (~> 0.8.1)
2828
uglifier
29-
unparser
29+
unparser (>= 0.2, < 0.4)
3030
webdrivers
3131

3232
PATH
3333
remote: ../../../hyper-state
3434
specs:
35-
hyper-state (1.0.alpha1.1)
36-
hyperstack-config (= 1.0.alpha1.1)
35+
hyper-state (1.0.alpha1.3)
36+
hyperstack-config (= 1.0.alpha1.3)
3737
opal (>= 0.11.0, < 0.12.0)
3838

3939
PATH
4040
remote: ../../../hyper-trace
4141
specs:
42-
hyper-trace (1.0.alpha1.1)
43-
hyperstack-config (= 1.0.alpha1.1)
42+
hyper-trace (1.0.alpha1.3)
43+
hyperstack-config (= 1.0.alpha1.3)
4444

4545
PATH
4646
remote: ../../../hyperstack-config
4747
specs:
48-
hyperstack-config (1.0.alpha1.1)
49-
libv8 (~> 6.3.0)
48+
hyperstack-config (1.0.alpha1.3)
5049
listen (~> 3.0)
51-
mini_racer (~> 0.1.15)
50+
mini_racer (~> 0.2.4)
5251
opal (>= 0.11.0, < 0.12.0)
5352
opal-browser (~> 0.2.0)
5453
uglifier
@@ -165,7 +164,7 @@ GEM
165164
rails-dom-testing (>= 1, < 3)
166165
railties (>= 4.2.0)
167166
thor (>= 0.14, < 2.0)
168-
libv8 (6.3.292.48.1-x86_64-darwin-15)
167+
libv8 (6.7.288.46.1-x86_64-darwin-15)
169168
listen (3.1.5)
170169
rb-fsevent (~> 0.9, >= 0.9.4)
171170
rb-inotify (~> 0.9, >= 0.9.7)
@@ -183,11 +182,12 @@ GEM
183182
mimemagic (0.3.2)
184183
mini_mime (1.0.1)
185184
mini_portile2 (2.3.0)
186-
mini_racer (0.1.15)
187-
libv8 (~> 6.3)
185+
mini_racer (0.2.4)
186+
libv8 (>= 6.3)
188187
minitest (5.11.3)
189188
msgpack (1.2.4)
190189
multi_json (1.13.1)
190+
net_http_ssl_fix (0.0.10)
191191
nio4r (2.3.1)
192192
nokogiri (1.8.5)
193193
mini_portile2 (~> 2.3.0)
@@ -337,7 +337,8 @@ GEM
337337
activemodel (>= 5.0)
338338
bindex (>= 0.4.0)
339339
railties (>= 5.0)
340-
webdrivers (3.4.3)
340+
webdrivers (3.6.0)
341+
net_http_ssl_fix
341342
nokogiri (~> 1.6)
342343
rubyzip (~> 1.0)
343344
selenium-webdriver (~> 3.0)
@@ -386,4 +387,4 @@ RUBY VERSION
386387
ruby 2.4.1p111
387388

388389
BUNDLED WITH
389-
1.16.0
390+
2.0.1

ruby/examples/misc/stock-tickers/app/hyperstack/components/app.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class App < HyperComponent
55
# @snake_case : reactive instance variable that will trigger rerenders
66
# @_snake_case : non-reactive instance variable that will never be mutated
77
# @CamelCase : a component param (this convention is inforced by Hyperstack)
8-
8+
99
before_mount { @symbols = Set.new }
1010

1111
def add_symbol
@@ -22,7 +22,7 @@ def add_symbol
2222
BS::Row(style: { marginTop: 20 }) do
2323
BS::Col(sm: 4) do
2424
BS::InputGroup(class: 'mb-3') do
25-
BS::FormControl(dom: set(:_symbol_input), placeholder: 'New Stock Market Symbol')
25+
BS::FormControl(ref: set_jq(:_symbol_input), placeholder: 'New Stock Market Symbol')
2626
.on(:enter) { add_symbol }
2727
BS::InputGroup::Append() { BS::Button() { 'Add' } }
2828
.on(:click) { add_symbol }

ruby/examples/misc/stock-tickers/app/hyperstack/components/display_ticker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class DisplayTicker < HyperComponent
22

3-
param :symbol # hyperstack will copy the param to @Symbol when it changes
4-
triggers :cancel # this is an outgoing event. You trigger it by calling cancel!
3+
param :symbol # hyperstack will copy the param to @Symbol when it changes
4+
fires :cancel # this is an outgoing event. You fire it by calling cancel!
55

66
# when the component mounts (is created) we create a corresponding ticker
77
# from our StockTicker store. We will never within the component change the

0 commit comments

Comments
 (0)