Hi there,

is there a way for a parent module to "subscribe" to a child module 
"event"? Here is the thing : I want to create a contact list. For that, I 
have a component named ContactList. Inside, I display all contacts like 
this :

renderContact: Contact.Model -> Html a
renderContact contact =
    li [] [Contact.view contact]

renderContacts: Model -> Html a
renderContacts model =
    model.contacts
    |> List.map renderContact
    |> ul []

view: Html a
view =
    div [] [
        renderContacts model
    ]

You can see that a contact is rendered by the Contact module, like this :

type alias Model = {
    firstname  : String
   ,name       : String
   ,phonenumber: String
}

view: Model -> Html a
view model =
     span[]
     [
         a [style contactfield] [text <| model.firstname ++ " " ++ 
model.name]
        ,span [style contactfield] [text <| model.phonenumber]
     ]

I would like to interact with the "a" element so that when the user click 
on it, it displays details about the selected contact. I started to write 
something like this :

type alias Model = {
    id: Int
   ,firstname  : String
   ,name       : String
   ,phonenumber: String
}

view: Model -> Html a
view model =
     span[]
     [
         a [style contactfield, on "click" (Json.map fetchDetail 
decodename), attribute "data-value" model.id)] [text <| model.firstname ++ 
" " ++ model.name]
        ,span [style contactfield] [text <| model.phonenumber]
     ]

Here, my model has improved with a new property : id. But the Contact 
module is not aware of any list of contacts, so I can't apply any filter in 
order to fetch the desired contact. Is there a way to simply realize this? 
Or maybe I'm on a totally wrong way...

Thanks!

-- 
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.

Reply via email to