I currently have a js library that will parse code and return either the 
html (render) or the AST (abstract syntax tree). The AST action per node is 
modifiable. I'd like use it in the following way:

For a single node type in the AST, I want to process it (rather than just 
rendering it to Html)
For every other node type, I want it to render Html, which the library does 
by default.

I'm curious about how to do the integration with Elm here. Should I use 
ports, managed effect module (like Time module), or a native module (like 
Http module)?

The guide discourages managed effects. If that's the solution here, I'm 
open to doing it.

Writing native modules seem like reaching into private interfaces and will 
cause me trouble down the line when new versions of elm come out. But in 
all the Html and Markdown modules I've seen, it just uses Native modules, 
presumably to avoid pitfall #2 below.

Hence, I think I need to use Ports. The easy part is sending a String of 
code into the port for parsing. I see two pitfalls with this approach:

   1. When I get back the single node type in the AST, I'd need to pass it 
   back to Elm as a JSON, and write a decoder to parse it. That seems like a 
   lot of work (Decoders take me a long time to write).
   2. For AST nodes rendered as Html, if I don't pass them back into Elm, I 
   assume that Elm wouldn't be able to do shadow dom diffing on it for 
   rendering. If I do pass them back into Elm, I'd have to write an Elm 
   Decoder from JSON into Html Msg, and that seems like a lot of work.

So what's the best way to tackle this? Is parsing a side effect? Would it 
make sense if this was a managed effect?

Wil

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to