On Tuesday, December 6, 2016 at 10:43:07 AM UTC, Rupert Smith wrote:
>
> Will go with the port for now.
>
There is something slightly annoying about the port, and that is that
processing the Cmd to call the port happens through setTimeout(function,
millis). This needs polyfilled on Nashorn, and uses Platform.runLater()
which runs it in an internal thread on the JavaFX engine.
All I want is an evaluation of a function from Value -> String (input Json
output rendered Html as a String). I don't really need to make use of the
event driven side of Elm at all.
To avoid doing this, I think I will go the route of defining some new
program types for static rendering server side. I may also want static
program types that produce Strings or Json. Once I've got rendering of
static Html working, I will look into moving all my code generation
templates over to Elm from StringTemplate. I really like having Elm as a
functional language for templating, it beats any crappy templating engine
I've ever tried.
I'm just now writing a constructor for StringPrograms, that will apply
htmlToString. I'm sticking with the Platform.Program type to provide the
structure to my Programs, 'flags' is taken as the input type, 'model' as
the output type, and 'init' is a function from the input to output types.
The msg type is Never, and subsciptions and updates are filled in with
noops.
I'll need to crank some javascript for my program types to provide a
convenient way to get hold of them in javascript land. Using a trick
similar to how Platform.program makes itself reachable from the outwith the
Elm compiled code:
function program(impl)
{
return function(flagDecoder)
{
return function(object, moduleName)
{
object['worker'] = function worker(flags)
{
'object' is the elm module, and I can set whatever fields I want on it when
constructing a program. I just need to set up a function to pass in the
input type and get back the output type.
Here are my Program types and the constructor signature that I am working
on for programs that render Html to a String:
type alias HtmlProgram =
Program Value (Html Never) Never
type alias JsonProgram =
Program Value Value Never
type alias StringProgram =
Program Value String Never
htmlToStringProgram : { init : Value -> Html Never } -> StringProgram
I've been able to get Elm running on Nashorn now. Its not fast... I think
Nashorn can be pretty quick, its just that it takes a long time for JIT to
kick in and optimize things and the first passes through the code are slow
with default settings. It took a minimal amount of polyfilling on Nashorn
to support it. All code is on github:
https://github.com/rupertlssmith/elm-server-side-renderer
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.