Skip to content

Commit f4b261b

Browse files
committed
extra hyper-store reference to be fixed
1 parent c1ca596 commit f4b261b

File tree

10 files changed

+94
-35
lines changed

10 files changed

+94
-35
lines changed

ruby/examples/docs/home-page/Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PATH
22
remote: ../../../hyper-component
33
specs:
4-
hyper-component (0.1)
5-
hyper-state (= 0.1)
6-
hyperstack-config (= 0.1)
4+
hyper-component (1.0.alpha1.1)
5+
hyper-state (= 1.0.alpha1.1)
6+
hyperstack-config (= 1.0.alpha1.1)
77
libv8 (~> 6.3.0)
88
mini_racer (~> 0.1.15)
99
opal (>= 0.11.0, < 0.12.0)
@@ -13,7 +13,7 @@ PATH
1313
PATH
1414
remote: ../../../hyper-spec
1515
specs:
16-
hyper-spec (0.1)
16+
hyper-spec (1.0.alpha1.1)
1717
capybara
1818
chromedriver-helper (= 1.2.0)
1919
libv8 (~> 6.3.0)
@@ -32,14 +32,14 @@ PATH
3232
PATH
3333
remote: ../../../hyper-state
3434
specs:
35-
hyper-state (0.1)
36-
hyperstack-config (= 0.1)
35+
hyper-state (1.0.alpha1.1)
36+
hyperstack-config (= 1.0.alpha1.1)
3737
opal (>= 0.11.0, < 0.12.0)
3838

3939
PATH
4040
remote: ../../../hyperstack-config
4141
specs:
42-
hyperstack-config (0.1)
42+
hyperstack-config (1.0.alpha1.1)
4343
libv8 (~> 6.3.0)
4444
listen (~> 3.0)
4545
mini_racer (~> 0.1.15)
@@ -159,7 +159,7 @@ GEM
159159
rails-dom-testing (>= 1, < 3)
160160
railties (>= 4.2.0)
161161
thor (>= 0.14, < 2.0)
162-
libv8 (6.3.292.48.1)
162+
libv8 (6.3.292.48.1-x86_64-darwin-15)
163163
listen (3.1.5)
164164
rb-fsevent (~> 0.9, >= 0.9.4)
165165
rb-inotify (~> 0.9, >= 0.9.7)

ruby/examples/docs/home-page/app/hyperstack/components/using_state.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class UsingState < HyperComponent
77
render(DIV) do
88
# the button method returns an HTML element
99
# .on(:click) is an event handeler
10-
button.on(:click) { mutate @show = !@show }
10+
button.on(:click) { toggle :show }
1111
DIV do
1212
input
1313
output

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PATH
22
remote: ../../../hyper-component
33
specs:
4-
hyper-component (1.0.alpha1)
5-
hyper-state (= 1.0.alpha1)
6-
hyperstack-config (= 1.0.alpha1)
4+
hyper-component (1.0.alpha1.1)
5+
hyper-state (= 1.0.alpha1.1)
6+
hyperstack-config (= 1.0.alpha1.1)
77
libv8 (~> 6.3.0)
88
mini_racer (~> 0.1.15)
99
opal (>= 0.11.0, < 0.12.0)
@@ -13,7 +13,7 @@ PATH
1313
PATH
1414
remote: ../../../hyper-spec
1515
specs:
16-
hyper-spec (1.0.alpha1)
16+
hyper-spec (1.0.alpha1.1)
1717
capybara
1818
chromedriver-helper (= 1.2.0)
1919
libv8 (~> 6.3.0)
@@ -32,20 +32,20 @@ PATH
3232
PATH
3333
remote: ../../../hyper-state
3434
specs:
35-
hyper-state (1.0.alpha1)
36-
hyperstack-config (= 1.0.alpha1)
35+
hyper-state (1.0.alpha1.1)
36+
hyperstack-config (= 1.0.alpha1.1)
3737
opal (>= 0.11.0, < 0.12.0)
3838

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

4545
PATH
4646
remote: ../../../hyperstack-config
4747
specs:
48-
hyperstack-config (1.0.alpha1)
48+
hyperstack-config (1.0.alpha1.1)
4949
libv8 (~> 6.3.0)
5050
listen (~> 3.0)
5151
mini_racer (~> 0.1.15)

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
class App < HyperComponent
2+
3+
# To make our code easy to read we use the following conventions for
4+
# instance variables (state):
5+
# @snake_case : reactive instance variable that will trigger rerenders
6+
# @_snake_case : non-reactive instance variable that will never be mutated
7+
# @CamelCase : a component param (this convention is inforced by Hyperstack)
8+
29
before_mount { @symbols = Set.new }
310

411
def add_symbol
5-
mutate @symbols << @SymbolInput.value.upcase
6-
@SymbolInput.value = ''
12+
mutate @symbols << @_symbol_input.value.upcase
13+
@_symbol_input.value = ''
714
end
815

916
render do
@@ -15,7 +22,7 @@ def add_symbol
1522
BS::Row(style: { marginTop: 20 }) do
1623
BS::Col(sm: 4) do
1724
BS::InputGroup(class: 'mb-3') do
18-
BS::FormControl(dom: set(:SymbolInput), placeholder: 'New Stock Market Symbol')
25+
BS::FormControl(dom: set(:_symbol_input), placeholder: 'New Stock Market Symbol')
1926
.on(:enter) { add_symbol }
2027
BS::InputGroup::Append() { BS::Button() { 'Add' } }
2128
.on(:click) { add_symbol }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
class BS < Hyperstack::Component::NativeLibrary
2+
# subclasses of Hyperstack::Component::NativeLibrary
3+
# are wrappers around JS component libraries.
4+
# once imported BS acts like an ordinary ruby module
5+
26
imports 'ReactBootstrap'
37
end

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
class DisplayTicker < HyperComponent
2-
param :symbol
3-
triggers :cancel
2+
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!
5+
6+
# when the component mounts (is created) we create a corresponding ticker
7+
# from our StockTicker store. We will never within the component change the
8+
# value of @_ticker so it begins with an underscore
9+
410
before_mount { @_ticker = StockTicker.new(@Symbol, 10.seconds) }
511

12+
# The status helper method renders some bootstrap columns depending on
13+
# the state of the ticker status. Internal to each StockTicker state
14+
# will be mutated, causing the component to rerender, and displaying new data.
15+
616
def status
717
case @_ticker.status
818
when :loading
@@ -16,6 +26,10 @@ def status
1626
end
1727
end
1828

29+
# Render the ticker. Most of the work is done in the status method, but
30+
# here we attach a close button using the BS `close` class (shown by an X)
31+
# when the close button is clicked we trigger the `cancel` event.
32+
1933
render do
2034
BS::Row() do
2135
BS::Col(sm: 1) { @Symbol.upcase }

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# def Hyperstack.naming_convention
2-
# :prefix_params
3-
# end
1+
# Each Hyperstack application should define a base
2+
# HyperComponent class. This where application wide
3+
# specific hooks can be added to customize behavior across
4+
# the application.
5+
6+
# In this case we attach hypertrace instrumentation to all
7+
# of our components so we get debug tracing of what is going on.
48

59
class HyperComponent
610
include Hyperstack::Component
Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1+
# Our StockTicker class abstracts out fetching and updating the stock
2+
# data for each ticker.
3+
4+
# By including the Hyperstack::State::Observable class we make our state
5+
# changes observable by other Components and Observables.
6+
17
class StockTicker
28
include Hyperstack::State::Observable
39

410
attr_reader :symbol
11+
12+
# state readers, these work like attr_readers, but
13+
# when the state is accessed (observed) it will be tracked
14+
# so the State system knows which components to update when
15+
# the state of the ticker changes
16+
517
state_reader :price
618
state_reader :time
719
state_reader :status
820
state_reader :reason
921

22+
# when the ticker is initialized we save the value of symbol and
23+
# the update_interval in instance variables.
24+
# @status is initialized to :loading, and all future changes will
25+
# be marked with a call to mutate.
26+
# Finally we make our first fetch of the symbols stock data.
27+
1028
def initialize(symbol, update_interval = 5.seconds)
1129
@symbol = symbol
12-
@status = :loading
1330
@update_interval = update_interval
31+
@status = :loading
1432
fetch
1533
end
1634

35+
# Each fetch sets up a call to get the symbols delayed quote data.
36+
# when the fetch returns we record the status, the price,
37+
# and the time of the quote.
38+
39+
# prefixing the state changes with mutate will signal any observers
40+
# that the state of this ticker has changed.
41+
42+
# once we have updated the state we setup another fetch cycle
43+
44+
# If the fetch fails, then we also update the status, and reason for the
45+
# failure. If the reason is that the symbol is unknown then we do not
46+
# need to reattempt the fetch, but otherwise we will keep trying.
47+
1748
def fetch
1849
HTTP.get("https://api.iextrading.com/1.0/stock/#{@symbol}/delayed-quote")
1950
.then do |resp|
2051
mutate @status = :success, @price = resp.json[:delayedPrice],
21-
@time = Time.at(resp.json[:delayedPriceTime] / 1000),
22-
@update_time = Time.now
52+
@time = Time.at(resp.json[:delayedPriceTime] / 1000)
2353
after(@update_interval) { fetch }
2454
end
2555
.fail do |resp|
@@ -28,12 +58,14 @@ def fetch
2858
end
2959
end
3060

61+
# just to demonstrate use of before_unmount - this is not needed
62+
# but if there were some other cleanups you needed you could put them here
63+
# however intervals (every) delays (after) and websocket receivers are all
64+
# cleaned up automatically
65+
3166
before_unmount do
32-
# just to demonstrate use of before_unmount - this is not needed
33-
# but if there were some other cleanups you needed you could put them here
34-
# however intervals (every) delays (after) and websocket receivers are all
35-
# cleaned up automatically
3667
puts "cancelling #{@symbol} ticker"
3768
end
3869
end
70+
3971
StockTicker.hypertrace instrument: :all

ruby/rails-hyperstack/Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ gem 'hyper-state', path: '../hyper-state'
44
gem 'hyper-component', path: '../hyper-component'
55
gem 'hyper-operation', path: '../hyper-operation'
66
gem 'hyper-model', path: '../hyper-model'
7-
gem 'hyper-store', path: '../hyper-store'
87
gem 'hyper-router', path: '../hyper-router'
98
gem 'hyper-spec', path: '../hyper-spec'
109
gem 'rails', '~> 5.2'

ruby/rails-hyperstack/lib/rails-hyperstack.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'hyperstack-config'
22
require 'rails/generators'
33
require 'hyper-state'
4-
require 'hyper-store'
54

65
# remove these once lap29 is released ...
76
Hyperstack.js_import 'react/react-source-browser', client_only: true, defines: ['ReactDOM', 'React']

0 commit comments

Comments
 (0)