Skip to content

Commit babeaa0

Browse files
committed
params now are camelcased plus misc fixes
1 parent 7b2ee6e commit babeaa0

File tree

30 files changed

+552
-112
lines changed

30 files changed

+552
-112
lines changed

ruby/examples/misc/stock-tickers/app/assets/javascripts/application.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
// Opal.Hyperstack.$const_get('Loader').$listen() // optional (port, false, poll_seconds) i.e. (8081, false, 1)
1414

15-
//
1615
//= require rails-ujs
1716
//= require activestorage
1817
//= require turbolinks
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
class App < HyperComponent
22
before_mount { @symbols = Set.new }
3-
render(DIV) do
4-
UL do
3+
4+
def add_symbol
5+
mutate @symbols << @SymbolInput.value.upcase
6+
@SymbolInput.value = ''
7+
end
8+
9+
render do
10+
BS::Container(style: { margin: 20 }) do
511
@symbols.sort.each do |symbol|
6-
LI(key: symbol) do
7-
DisplayTicker(symbol: symbol)
8-
.on(:cancel) { mutate @symbols.delete(symbol) }
12+
DisplayTicker(symbol: symbol, key: symbol)
13+
.on(:cancel) { mutate @symbols.delete(symbol) }
14+
end
15+
BS::Row(style: { marginTop: 20 }) do
16+
BS::Col(sm: 4) do
17+
BS::InputGroup(class: 'mb-3') do
18+
BS::FormControl(ref: assign_to(:SymbolInput), placeholder: 'New Stock Market Symbol')
19+
.on(:enter) { add_symbol }
20+
BS::InputGroup::Append() { BS::Button() { 'Add' } }
21+
.on(:click) { add_symbol }
22+
end
923
end
1024
end
1125
end
12-
INPUT(placeholder: 'enter a new stock symbol')
13-
.on(:key_down) do |evt|
14-
next unless evt.key_code == 13
15-
mutate @symbols << evt.target.value.upcase
16-
evt.target.value = ''
17-
end
1826
end
1927
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class BS < Hyperstack::Component::NativeLibrary
2+
imports 'ReactBootstrap'
3+
end
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
class DisplayTicker < HyperComponent
22
param :symbol
3-
param :on_cancel, type: Proc
4-
before_mount { @ticker = StockTicker.new(params.symbol, 10.seconds) }
3+
raises :cancel
4+
before_mount { @ticker = StockTicker.new(@Symbol, 10.seconds) }
55

66
def status
77
case @ticker.status
88
when :loading
9-
'loading...'
9+
BS::Col(sm: 10) { 'loading...' }
1010
when :success
11-
"current price: #{@ticker.price}"
11+
BS::Col(class: 'text-right', sm: 3) { 'price' }
12+
BS::Col(class: 'text-right', sm: 3) { '%.2f' % @ticker.price }
13+
BS::Col(sm: 4) { "at #{@ticker.time.strftime('%I:%M:%S')}" }
1214
when :failed
13-
"failed to get quote: #{@ticker.reason}"
15+
BS::Col(sm: 10) { "failed to get quote: #{@ticker.reason}" }
1416
end
1517
end
1618

17-
render(DIV) do
18-
SPAN { "#{params.symbol.upcase} #{status}" }
19-
BUTTON { 'cancel' }.on(:click) { params.on_cancel } unless @ticker.status == :loading
19+
render do
20+
BS::Row() do
21+
BS::Col(sm: 1) { @Symbol.upcase }
22+
status
23+
BS::Col(sm: 1) do
24+
BS::Button(class: :close) { "\u00D7" }
25+
.on(:click) { cancel! } unless @ticker.status == :loading
26+
end
27+
end
2028
end
2129
end

ruby/examples/misc/stock-tickers/app/hyperstack/stores/stock_ticker.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ class StockTicker
33

44
attr_reader :symbol
55
state_reader :price
6+
state_reader :time
67
state_reader :status
78
state_reader :reason
89

910
def initialize(symbol, update_interval = 5.seconds)
10-
puts "creating ticker for #{symbol}"
1111
@symbol = symbol
1212
@status = :loading
1313
@update_interval = update_interval
1414
fetch
1515
end
1616

1717
def fetch
18-
puts "fetching #{@symbol}"
1918
HTTP.get("https://api.iextrading.com/1.0/stock/#{@symbol}/delayed-quote")
2019
.then do |resp|
21-
mutate @status = :success, @price = resp.json[:delayedPrice]
20+
mutate @status = :success, @price = resp.json[:delayedPrice],
21+
@time = Time.at(resp.json[:delayedPriceTime] / 1000)
2222
after(@update_interval) { fetch }
2323
end
2424
.fail do |resp|

ruby/examples/misc/stock-tickers/app/views/layouts/application.html.erb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,50 @@
77

88
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
99
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10+
<link
11+
rel="stylesheet"
12+
href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css"
13+
crossorigin="anonymous"
14+
>
15+
<%# <script src="https://unpkg.com/@material-ui/[email protected]/umd/material-ui.development.js" crossorigin="anonymous"></script>
16+
<!-- <script src="https://unpkg.com/@material-ui/core/umd/material-ui.production.min.js" crossorigin="anonymous"></script> -->
17+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
18+
<script>
19+
window.MUI = window['material-ui']
20+
const theme = MUI.createMuiTheme({
21+
palette: {
22+
primary: {
23+
light: MUI.colors.purple[300],
24+
main: MUI.colors.purple[500],
25+
dark: MUI.colors.purple[700],
26+
},
27+
secondary: {
28+
light: MUI.colors.green[300],
29+
main: MUI.colors.green[500],
30+
dark: MUI.colors.green[700],
31+
},
32+
},
33+
typography: {
34+
useNextVariants: true,
35+
},
36+
});
37+
const styles = theme => ({
38+
root: {
39+
textAlign: 'center',
40+
paddingTop: theme.spacing.unit * 20,
41+
},
42+
icon: {
43+
marginRight: theme.spacing.unit,
44+
},
45+
});
46+
</script> %>
47+
1048
</head>
1149

1250
<body>
1351
<%= yield %>
52+
<script src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.js" crossorigin></script>
53+
54+
1455
</body>
1556
</html>

ruby/examples/misc/stock-tickers/config/initializers/hyperstack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hyperstack.configuration do |config|
2-
config.prerendering = :on
2+
config.prerendering = :off
33
config.import 'jquery', client_only: true
44
config.import 'hyperstack/component/jquery', client_only: true
55
config.import 'browser/interval'
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"name": "smoke-test",
33
"private": true,
4-
"dependencies": {}
4+
"dependencies": {
5+
"@material-ui/core": "^3.4.0"
6+
}
57
}

0 commit comments

Comments
 (0)