mdgriffith / design-discussion-elm-ui-2

A repo for discussing changes to Elm UI 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change Element.table to accept data as a separate argument

jackwilsdon opened this issue · comments

Element.table accepts data as part of a record for its second argument:

table :
    List (Attribute msg)
    -> { data : List records
       , columns : List (Column records msg)
       }
    -> Element msg

I think it would be useful to have data as the third argument instead:

table :
    List (Attribute msg)
    -> List (Column records msg)
    -> List records
    -> Element msg

This change would enable the use of pipes and currying with Element.table:

people
    |> List.filter (.name >> (==) "Example")
    |> List.sortBy .age
    |> Element.table []
        [ { header = text "Name"
          , width = fill
          , view = \{ name } -> text name
          }
        , { header = text "Age"
          , width = fill
          , view = \{ age } -> text (String.fromInt age)
          }
        ]
tableOfPeople : List Person -> Element msg
tableOfPeople =
    Element.table []
        [ { header = text "Name"
          , width = fill
          , view = \{ name } -> text name
          }
        , { header = text "Age"
          , width = fill
          , view = \{ age } -> text (String.fromInt age)
          }
        ]

Currently, the equivalent of the above examples look like this:

Element.table []
    { data =
        people
            |> List.filter (.name >> (==) "Example")
            |> List.sortBy .age
    , columns =
        [ { header = text "Name"
          , width = fill
          , view = \{ name } -> text name
          }
        , { header = text "Age"
          , width = fill
          , view = \{ name } -> text name
          }
        ]
    }
tableOfPeople : List Person -> Element msg
tableOfPeople people =
    Element.table []
        { data = people
        , columns =
            [ { header = text "Name"
              , width = fill
              , view = \{ name } -> text name
              }
            , { header = text "Age"
              , width = fill
              , view = \{ age } -> text (String.fromInt age)
              }
            ]
        }

Related Slack thread.

I guess functions like indexedTable would also benefit from such a change - I'm not sure if there is anything else in elm-ui that accepts data like Element.table but it'd be good to consider those too.