On of the key recommendations of Elm Architecture is to have your messages
be just data.

Your approach is somewhat similar to the approach of elm-sortable-table
(except for the Cmds and Subs).

Without  using Cmds and/or Subs it is an interesting approach if you use it
for managing very small bits of state (the open/close status of a dropdown)
but I'm afraid that it might bring performance problems if you use it for
the entirety of the app.
You basically have to computer all the possible future states of the app.


On Thu, Aug 24, 2017 at 10:10 AM, Vlad GURDIGA <gurd...@gmail.com> wrote:

> Hey Elm-guys and Elm-gals! 👋
>
> I have this toy-project
> <https://github.com/gurdiga/xo.elm/tree/9fe9bd1b9f7cb13b6653ec55d9e873033e8930ed>
> 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
> <http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html#map>)
> between nested components to be counterintuitive, I left out messages, for
> the most part. I only have one
> <https://github.com/gurdiga/xo.elm/blob/9fe9bd1b9f7cb13b6653ec55d9e873033e8930ed/src/Main.elm#L33-L41>
> 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
> <https://github.com/gurdiga/xo.elm/blob/9fe9bd1b9f7cb13b6653ec55d9e873033e8930ed/src/Main.elm#L64>,
> and from then on I use callback-style functions
> <https://github.com/gurdiga/xo.elm/blob/9fe9bd1b9f7cb13b6653ec55d9e873033e8930ed/src/Dosar.elm#L31-L42>
> for wiring up the nested components:
>
> view : Dosar -> (Dosar -> Cmd msg -> Sub msg -> msg) -> Html msgview (Dosar 
> data) callback =
>     let
>         c data =
>             callback (Dosar data)
>     in
>         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
> <https://github.com/gurdiga/xo.elm/blob/9fe9bd1b9f7cb13b6653ec55d9e873033e8930ed/src/Widgets/Fields.elm#L27-L34>
> :
>
> 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.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

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