module salix::demo::basic::Counter
rascal-0.34.0
salix-core-0.2.3
Usage
import salix::demo::basic::Counter;
Source code
http://github.com/usethesource/salix-core/src/main/rascal/salix/demo/basic/Counter.rsc
Dependencies
import salix::App;
import salix::HTML;
import salix::Index;
function counterApp
SalixApp[Model] counterApp(str id = "root")
= makeApp(id, init, withIndex("Counter", id, view), update);
function counterWebApp
App[Model] counterWebApp()
= webApp(
counterApp(),
|project://salix/src/main/rascal|
);
alias Model
tuple[int count]
function init
Model init() = <0>;
data Msg
data Msg
= inc()
| dec()
;
function update
Model update(Msg msg, Model m) {
switch (msg) {
case inc(): m.count += 1;
case dec(): m.count -= 1;
}
return m;
}
function view
void view(Model m) {
h2(id("header"), "My first counter app in Rascal");
button(onClick(inc()), "+");
div(id("thecount"), "<m.count>");
button(onClick(dec()), "-");
}