-
Notifications
You must be signed in to change notification settings - Fork 2
/
step-by-step-example.html
178 lines (111 loc) · 6.38 KB
/
step-by-step-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html id="step-by-step-example" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#424" />
<meta name="google-site-verification" content="hPhlgOa-i_VITSyOHYwXB0xF0ZsZa_1K7z4LQc1nTDg" />
<link rel="apple-touch-icon" sizes="192x192" href="resources/logo-192.png" />
<link rel="apple-touch-icon" sizes="180x180" href="resources/logo-180.png" />
<link rel="apple-touch-icon" sizes="167x167" href="resources/logo-167.png" />
<link rel="apple-touch-icon" sizes="152x152" href="resources/logo-152.png" />
<link rel="apple-touch-icon" sizes="144x144" href="resources/logo-144.png" />
<link rel="apple-touch-icon" sizes="120x120" href="resources/logo-120.png" />
<link rel="apple-touch-icon" sizes="114x114" href="resources/logo-114.png" />
<link rel="apple-touch-icon" sizes="76x76" href="resources/logo-76.png" />
<link rel="apple-touch-icon" sizes="76x76" href="resources/logo-72.png" />
<link rel="apple-touch-icon" sizes="60x60" href="resources/logo-60.png" />
<link rel="apple-touch-icon" sizes="57x57" href="resources/logo-57.png" />
<link rel="icon" sizes="192x192" href="resources/logo-192.png" />
<link rel="icon" sizes="128x128" href="resources/logo-128.png" />
<link rel="icon" sizes="96x96" href="resources/logo-96.png" />
<link rel="icon" sizes="64x64" href="resources/logo-64.png" />
<link rel="icon" sizes="48x48" href="resources/logo-48.png" />
<link rel="icon" sizes="32x32" href="resources/logo-32.png" />
<link rel="icon" sizes="16x16" href="resources/logo-16.png" />
<link rel="stylesheet" href="resources/style.css" />
<title>ScalaLoci: Step-by-Step Example</title>
<meta name="description" content="A chat application in five steps example for the ScalaLoci programming language." />
<link rel="canonical" href="https://scala-loci.github.io/step-by-step-example.html" />
<meta property="og:title" content="ScalaLoci: Step-by-Step Example" />
<meta property="og:description" content="A chat application in five steps example for the ScalaLoci programming language." />
<meta property="og:locale" content="en_US" />
<meta property="og:url" content="https://scala-loci.github.io/step-by-step-example.html" />
<meta property="og:image" content="resources/logo-192.png" />
</head>
<body>
<header>
<h1><a href="index.html">ScalaLoci</a></h1>
<p>Step-by-Step Example</p>
</header>
<main>
<section>
<label for="step-1"></label>
<label for="step-2"></label>
<label for="step-3"></label>
<label for="step-4"></label>
<label for="step-5"></label>
<input type="radio" name="step" id="step-1" />
<input type="radio" name="step" id="step-2" />
<input type="radio" name="step" id="step-3" />
<input type="radio" name="step" id="step-4" />
<input type="radio" name="step" id="step-5" />
<p>The example demonstrates the design of a chat application in five steps</p>
<ol>
<li>Declaring a <em>Server</em></li>
<li>Declaring a <em>Client</em></li>
<li>Declaring a <em>message</em> event on the <em>Client</em> and firing the event for every user input</li>
<li>Declaring a <em>publicMessage</em> event on the <em>Server</em> aggregating all events from the clients</li>
<li>Declaring a client-side observer for the server-side <em>publicMessage</em> event</li>
</ol>
<figure>
<figure>
<pre><code>@<span class="dsl">multitier</span> <span class="keyword">object</span> Chat {
<span class="keyword">trait</span> Server <span class="keyword">extends</span> Peer { <span class="keyword">type</span> <span class="dsl">Tie</span> <: <span class="dsl">Multiple</span>[Client] }
}</code></pre>
<img width="465" height="324" src="resources/chat.svg?segment-0#segment-0" alt="A single server" />
<figcaption><em>Server</em> declaration</figcaption>
</figure>
<figure>
<pre><code>
<span class="keyword">trait</span> Client <span class="keyword">extends</span> Peer { <span class="keyword">type</span> <span class="dsl">Tie</span> <: <span class="dsl">Single</span>[Server] }
</code></pre>
<img width="465" height="324" src="resources/chat.svg?segment-1#segment-1" alt="Two clients" />
<figcaption><em>Client</em> declaration</figcaption>
</figure>
<figure>
<pre><code>
<span class="keyword">val</span> message = <span class="dsl">placed</span>[Client] { Evt[String]() }
<span class="dsl">placed</span>[Client].main {
<span class="keyword">for</span> (line <- io.Source.stdin.getLines)
message fire line
}
</code></pre>
<img width="465" height="324" src="resources/chat.svg?segment-2#segment-2" alt="A message event, placed on every client" />
<figcaption>Event <em>message</em> declaration</figcaption>
</figure>
<figure>
<pre><code>
<span class="keyword">val</span> publicMessage = <span class="dsl">placed</span>[Server] {
message.<span class="dsl">asLocalFromAllSeq</span> map { <span class="keyword">case</span> (_, message) => message }
}
</code></pre>
<img width="465" height="324" src="resources/chat.svg?segment-3#segment-3" alt="Messages are sent from the clients' message events to the publicMessage event on the server" />
<figcaption>Event <em>publicMessage</em> declaration</figcaption>
</figure>
<figure>
<pre><code>
publicMessage.<span class="dsl">asLocal</span> observe println
</code></pre>
<img width="465" height="324" src="resources/chat.svg?segment-4#segment-4" alt="Messages are forwarded from the publicMessage event on the server to all clients, which print them to their console" />
<figcaption>Remote observer for <em>publicMessage</em> declaration</figcaption>
</figure>
<figcaption>Incremental <em>Chat</em> example</figcaption>
</figure>
</section>
</main>
<footer>
<p>ScalaLoci is a research project held in the <em>Reactive Programming Technology</em> group at <em>TU Darmstadt</em>.</p>
</footer>
</body>
</html>