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

Commit 9152908

Browse files
author
Barrie Hadfield
committed
improved examples
1 parent b403966 commit 9152908

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

clock.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

index.html

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,68 @@
1616
<script src="https://rawgit.com/ruby-hyperloop/hyperloop-js/master/hyperloop.min.js"></script>
1717

1818
<script type="text/ruby">
19-
class SimpleComponent < Hyperloop::Component
19+
class TopLevelComponent < Hyperloop::Component
2020
render(DIV) do
21-
BUTTON { 'Push the button' }.on(:click) do
22-
alert 'You did it!'
21+
H1 { "Components, Stores and Operations" }
22+
TypeAlong()
23+
ButtonComponent()
24+
Clock()
25+
end
26+
end
27+
28+
class MyStore < Hyperloop::Store
29+
state :value, reader: true, scope: :class
30+
31+
def self.set_value value
32+
mutate.value value
33+
end
34+
35+
def self.clear
36+
mutate.value ""
37+
end
38+
end
39+
40+
class ClearOp < Hyperloop::Operation
41+
step { puts "about to clear everything" }
42+
step { MyStore.clear }
43+
end
44+
45+
class ButtonComponent < Hyperloop::Component
46+
render(DIV) do
47+
H2 { "Here is a button" }
48+
BUTTON { 'See the value' }.on(:click) do
49+
alert "MyStore value is '#{ MyStore.value }' "
2350
end
51+
BUTTON { 'Clear' }.on(:click) { ClearOp.run }
52+
end
53+
end
54+
55+
class TypeAlong < Hyperloop::Component
56+
render(DIV) do
57+
H2 { "MyStore value is '#{ MyStore.value }'" }
58+
INPUT(type: :text, value: MyStore.value ).on(:change) do |e|
59+
MyStore.set_value e.target.value
60+
end
61+
end
62+
end
63+
64+
class Clock < Hyperloop::Component
65+
param format: '%a, %e %b %Y %H:%M:%S'
66+
before_mount do
67+
mutate.time Time.now.strftime(params.format)
68+
every(1) { mutate.time Time.now.strftime(params.format) }
69+
end
70+
71+
render(DIV) do
72+
H2 { "And a clock" }
73+
"The time is #{state.time}"
2474
end
2575
end
2676
</script>
77+
2778
</head>
2879

2980
<body>
30-
<div data-hyperloop-mount="SimpleComponent">
31-
</div>
81+
<div data-hyperloop-mount="TopLevelComponent"></div>
3282
</body>
3383
</html>

0 commit comments

Comments
 (0)