Reputation: 612
How do I use this AnswerList somewhere so events are addressed properly? I'm struggling with this for too long already :/
module AnswersList (Model, Action, update, view, Answer) where
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class)
type alias Answer =
{ id : Int
, answer : String
, points : Int
, visible : Bool
}
type alias Model = List Answer
-- actions
type Action = ShowAnswer Int
update action model =
case action of
ShowAnswer aid ->
let newAnswer a = if a.id == aid then { a | visible <- True } else a
in
List.map newAnswer model
-- view
view : Signal.Address Action -> Model -> Html
view address model =
div [class "list-group"]
(List.map (viewAnswer address) model)
viewAnswer : Signal.Address Action -> Answer -> Html
viewAnswer address answer =
let answerText = if answer.visible then answer.answer else "........"
in
div [class "list-group-item", onClick address (ShowAnswer answer.id) ] [text answerText]
Now in other module view I want to simply add some AnswersList to view and I don't know how to achieve it :/ Could you help me?
I have some other module
model = { answers: AnswerList.model }
and I would like to pass events so to AnswerList.update
somehow will handle them.
Upvotes: 1
Views: 240
Reputation: 612
Ok what I really needed was this example https://github.com/evancz/elm-architecture-tutorial/blob/master/examples/2/CounterPair.elm from https://github.com/evancz/elm-architecture-tutorial and yeah it totally makes sense :)
Upvotes: 2