module salix::demo::basic::Resize
rascal-0.43.0
org.rascalmpl.salix-core-0.3.0
Usage
import salix::demo::basic::Resize;
Dependencies
import salix::HTML;
import salix::App;
import salix::Core;
import salix::Index;
import IO;
function resizeWebApp
App[Model] resizeWebApp() = webApp(resizeApp(), |project://salix/src/main/rascal|);
function resizeApp
SalixApp[Model] resizeApp(str id = "root")
= makeApp(id, init, withIndex("Resizable demo", id, view), update, subs=subs);
alias Model
tuple[bool resizable]
function init
Model init() = <false>;
data Msg
data Msg
= toggleResize()
| resized(Resize res)
;
function subs
list[Sub] subs(Model m) = [ observeResize(resized, "thing") | m.resizable ];
function update
Model update(Msg msg, Model t) {
switch (msg) {
case resized(<num i, num b>): println("Resized: <i>, <b>");
case toggleResize(): t.resizable = !t.resizable;
}
return t;
}
function view
void view(Model m) {
h2("Observing resizes");
map[str, str] resizable = m.resizable ? ("resize": "both", "overflow": "auto") : ();
div(style(resizable + ("border": "solid", "width": "200px")), id("thing"), () {
p("is this resizable? <m.resizable>");
});
button(onClick(toggleResize()), "Toggle resizable: <m.resizable>");
}