8000 Keyed nodes · Issue #10 · pzavolinsky/elmx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Keyed nodes #10

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

Closed
daig opened this issue Oct 23, 2016 · 4 comments
Closed

Keyed nodes #10

daig opened this issue Oct 23, 2016 · 4 comments

Comments

@daig
Copy link
daig commented Oct 23, 2016

In JSX there's special syntax for keyed nodes in a list:

<ul>{notes |> map (\ note -> <li key={note.id}>{note.task}</li>)}</ul>

There is functionality for keyed nodes in Elm but so far as I can tell they use a different datastructure from normal nodes. So, it will be tricky to implement this transform as it
A possible first step is, rather than nesting like above (#9), simply translate <li key={k}>{stuff}</li> to (k,li [] [stuff]) and require the keyed parent node explicitly.

@pzavolinsky
Copy link
Owner

Hi @daig , I haven't used keyed elements in Elm, but this seems like something worth implementing.

I like the idea of translating a node with a key={k} attribute into (k,node), but I'll have to look into promoting the parent node into Html.Keyed.node.

Can you send me a working example in plain Elm?

@daig
Copy link
Author
daig commented Oct 26, 2016

The example I'm working with is:

import List
import Uuid exposing (Uuid)
import Html exposing (li)
import Note
import Html.Keyed as Keyed
type alias Notes = List (Uuid,Note.Model)
view : Notes -> Html Msg
view notes = Keyed.ul [] (notes |> List.map (\(id,note) -> (toString id, li [] [Note.view note])))

@pzavolinsky
Copy link
Owner

Hi @daig , I've just pushed elmx@1.0.8 and Atom's language-elmx@1.2.9 with keyed node support.

I added some examples in the README and here.

I've also added some examples at the end of the live demo.

Thanks for suggesting this feature!

Cheers!

@pzavolinsky
Copy link
Owner

Here's your example in elmx:

import Html
import Html.Attributes
import Html.Keyed
import List
import Uuid exposing (Uuid)
import Note
type alias Notes = List (Uuid,Note.Model)


view : Notes -> Html Msg
view notes =
  let
    items = notes |> List.map (\(id,note) -> <li key={toString id}>{Note.view note}</li>)
  in
    <ul keyed>{:items}</ul>

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
0