I am creating a salix webapp and I am trying to use codeMirror as per the salix examples.
I am unable to execute the codeMirror example in the salix.demo.basic, even though I can easily execute all the other examples in basic, so I'm wondering if anything has changed since these were written.
The code I am using:
module salix::demo::basic::CodeMirror
import salix::HTML;
import salix::App;
import salix::lib::CodeMirror;
import IO;
alias Model = tuple[list[Msg] changes, str src];
SalixApp[str] cmApp(str id = "root") = makeApp(id, init, view, update, parser=parseMsg);
App[str] cmWebApp()
= webApp(
cmApp(),
|project://projectName/src/salix/demo/basic/index.html|,
|project://projectName/src|
);
Model init()
= <[], "function hello() {\n console.log(\'Hello world\');\n}">;
data Msg
= myChange(int, int, int, int, str, str)
;
Model update(Msg msg, Model model) {
switch (msg) {
case m:myChange(int _, int _, int _, int _, str _, str _):{
println("Update called");
model.changes += [m];
}
}
return model;
}
void view(Model model) {
div(() {
h2("Code Mirror demo");
div(() {
codeMirror("cm", style(("height": "auto")), onChange(myChange),
mode("javascript"), lineNumbers(true), \value(model.src));
});
for (Msg m <- model.changes) {
text(m);
text("; ");
}
});
}
In my app I have managed to display the codeMirror example as so:
codeMirror("cm", onChange(cmChange), style(("height": "50%")),
lineNumbers(true), \value(model.projectViewInfo.src), lineWrapping(true), class("cm-s-3024-night"));
but the change message is never sent (cmChange
) and the source is never updated. So it is partially working for me.
This example can also be found in the salix library https://github.com/usethesource/salix/tree/master/src/salix/demo/basic