Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Elmx #9

Open
daig opened this issue Oct 23, 2016 · 1 comment
Open

Nested Elmx #9

daig opened this issue Oct 23, 2016 · 1 comment

Comments

@daig
Copy link

daig commented Oct 23, 2016

Hi, great library!
Sometimes I'd like to nest Elmx syntax, for example when mapping over children:

<ul>{notes |> List.map (\ note -> <li>{view note}</li>)}</ul>

but this doesn't get the right result.
Is there a fundamental barrier to nesting, or is it just extra tricky to implement?

@daig daig mentioned this issue Oct 23, 2016
@pzavolinsky
Copy link
Owner

Hi @daig the short answer is that this is tricky to implement.

The detailed answer follows:

I'm currently using htmlparser2 to parse the Elmx (as HTML) into an AST and then from there generate the Elm code. The pro of this approach is that it keeps the elmx code small, the trade-off is that invalid HTML might break the parser and yield the wrong results (like in your example above).

Of course, this a sub-optimal implementation since not every Elmx needs to be a valid HTML, but it was a pragmatic decision (that we can review provided we find a better parser or an alternative approach).

For the time being, you can overcome this limitation by rewriting this:

<ul>{:notes |> List.map (\ note -> <li>{view note}</li>)}</ul>

like this:

let
  items = notes |> List.map (\ note -> <li>{view note}</li>)
in
  <ul>{:items}</ul>

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants