Hey Elm-guys and Elm-gals! 👋

I have this toy-project 
where I’m getting my feet wet with Elm, and I’ve found an approach to 
compose view function that’s a bit different than what The Elm Architecture 
recommends. 🤓

Because I found message transformation (mapping 
between nested components to be counterintuitive, I left out messages, for 
the most part. I only have one 
for the whole app: 🙃

type Msg
    = Update Model (Cmd Msg) (Sub Msg)

update : Msg -> Model -> ( Model, Cmd Msg )update msg model =
    case msg of
        Update model cmd sub ->
            ( { model | subscription = sub }, cmd )

Only the top component references it 
and from then on I use callback-style functions 
for wiring up the nested components:

view : Dosar -> (Dosar -> Cmd msg -> Sub msg -> msg) -> Html msgview (Dosar 
data) callback =
        c data =
            callback (Dosar data)
        div []
            [ h1 [] [ text "Dosar nou" ]
            , Temei.view data.temei (\v -> c { data | temei = v })
            , DocumentExecutoriu.view data.documentExecutoriu (\v -> c { data | 
documentExecutoriu = v } Cmd.none Sub.none)
            , Actiune.view data.actiune (\v -> c { data | actiune = v })

and also for event handlers 

unlabeledTextField : String -> (String -> msg) -> List (Html 
msg)unlabeledTextField defaultValue callback =
    [ input
        [ value defaultValue
        , onInput callback

It seems to work well so far, and coming from JS I find this style a bit 
more familiar conceptually: I only have functions and values. 🤓

I am at about 184K of Elm now, and I’m wondering if anyone else have tried 
to do it this way and maybe found some gotchas that I should be aware of. 
In particular, with regards to how the code compiles to JS and maybe other 
Elm’s inner workings. 🤔

Cheers! 🤠

(NOTE: If you want to browse the code, please use this 
revision: https://github.com/gurdiga/xo.elm/tree/9fe9bd1. After that I’m 
bringing in elm-mdl 
<http://package.elm-lang.org/packages/debois/elm-mdl/8.1.0>, and the code 
will probably get too noisy for the purpose of this conversation. 🙂)

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