File tree Expand file tree Collapse file tree 5 files changed +21
-9
lines changed
ruby/examples/misc/stock-tickers Expand file tree Collapse file tree 5 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class App < HyperComponent
1212 INPUT ( placeholder : 'enter a stock symbol' ) . on ( :key_down ) do |evt |
1313 next unless evt . key_code == 13
1414 mutate @symbols << evt . target . value
15+ evt . target . value = ''
1516 end
1617 end
1718end
Original file line number Diff line number Diff line change 11class DisplayTicker < HyperComponent
22 param :symbol
3- before_mount { @ticker = StockTicker . new ( params . symbol ) }
3+ before_mount { @ticker = StockTicker . new ( params . symbol , 10 . seconds ) }
44 render ( DIV ) do
55 "#{ params . symbol . upcase } current price: #{ @ticker . price } "
66 end
Original file line number Diff line number Diff line change 11class StockTicker
22 include Hyperstack ::State ::Observable
33
4+ state_reader :price
5+ attr_reader :symbol
6+
7+ def initialize ( symbol , update_interval = 5 . minutes )
8+ @symbol = symbol
9+ fetch
10+ every ( update_interval ) { fetch }
11+ end
12+
413 def fetch
14+ puts "fetching #{ @symbol } "
515 HTTP . get ( "https://api.iextrading.com/1.0/stock/#{ @symbol } /delayed-quote" ) . then do |response |
616 mutate @price = response . json [ :delayedPrice ]
717 end
818 end
919
10- def initialize ( symbol , update_interval = 5 . minutes )
11- @symbol = symbol
12- fetch
13- every ( update_interval ) { fetch }
20+ before_unmount do
21+ # just to demonstrate use of before_unmount - this is not needed
22+ # but if there were some other cleanups you needed you could put them here
23+ # however intervals (every) delays (after) and websocket receivers are all
24+ # cleaned up automatically
25+ puts "cancelling #{ @symbol } "
1426 end
1527
16- state_reader :price
17- attr_reader :symbol
1828end
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html >
33 < head >
4- < title > SmokeTest </ title >
4+ < title > Stock Tickers Example </ title >
55 <%= csrf_meta_tags %>
66 <%= csp_meta_tag %>
77
Original file line number Diff line number Diff line change 11Hyperstack . configuration do |config |
22 config . prerendering = :on
3- config . import 'hyperstack-jquery'
3+ config . import 'jquery' , client_only : true
4+ config . import 'hyperstack/component/jquery' , client_only : true
45 config . import 'browser/interval'
56 config . import 'active_support'
67 config . import 'hyperstack/hotloader' , client_only : true if Rails . env . development?
You can’t perform that action at this time.
0 commit comments