type alias Model a =
{ a
| routes : List Route
, hovered : Maybe Int
, selected : Maybe Int
, map : Map.InternalModel
, table : Table.InternalModel
, profile : Profile.InternalModel
}
type alias Model a =
{ a
| route : List Route
, selected : Maybe Int
, profile : InternalModel
}
type alias Model a =
{ a
| route : List Route
, selected : Maybe Int
, hovered : Maybe Int
, table : InternalModel
}
init : a -> Model a
init foo =
{foo | table = initInternal}
init : Model
init =
{routes = []}
|> Table.init
|> Profile.init
type alias Model a =
{ a
| shared : Shared.Shared
, map : Map.InternalModel
, table : Table.InternalModel
, profile : Profile.InternalModel
}
init : Model
init =
{ shared = Shared.init
, map = Map.init
, table = Table.init
, profile = Profile.init
}
Is it correct that your issue
could be addressed by not bringing back arbitrary record extension in
expressions via the pre-0.16 syntax { ... | ... = ... }
, but only bringing back constructor functions for extensible records? That is, if from the table at https://github.com/elm-lang/elm-platform/blob/master/upgrade-docs/0.16.md#updating-syntax
only language change in the row “record constructors that add fields”
were reverted, but not the language changes in the other rows?
Also relevant in this context, then: https://github.com/elm-lang/elm-compiler/issues/1308.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
init : a -> Model a
init old =
{ old | newField = 4 }
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
You should be able to do that.
If you have
type alias Model a =
{ a | newField : Int }
then
init : a -> Model a
init old = Model old 4
is exactly equivalent (in pre-0.16 Elm) to
init : a -> Model a
init old = { old | newField = 4 }
So where’s the problem?
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
init : a -> Model a
init old = Model 4 old
But the point stands, that you would only need the row "record constructors that add fields" from https://github.com/elm-lang/elm-platform/blob/master/upgrade-docs/0.16.md#updating-syntax to be reverted.So far this pattern is serving me very well. I keep meaning to write up a blog series about it but haven't found a gap in work to do so yet!
I'm building an application to help ship captains create routes. My question is about the organization of the model of this application.
The application currently has one page containing three widgets
Sorry to ramble on about this, but it's been a thorn in my side for a long time now.
I would really appreciate any thoughts on this.
You are on the road to #2, so my macro-level suggestion would be to go back to #1. :)
On Tuesday, August 23, 2016 at 11:24:22 AM UTC-6, Richard Feldman wrote:You are on the road to #2, so my macro-level suggestion would be to go back to #1. :)#1 also ends up making utterly *huge* model and message unions though, with extremely non-reusable parts. :-)
For sure! :D
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/NPOcF4Dle2w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
At work we have 36,000 LoC of production Elm. One of our most complicated pages has a Model with 55 fields in it, and a Msg with 40 type constructors, and it feels nice to maintain. A year ago it was a bunch of nested React components and everyone dreaded touching it. Now we make changes to it all the time and it's no big deal.
Just break it into modules so your similar functions are grouped together in files. Use them just like you already are.
While I understand that not breaking things up too often is sound advice in elm, I still think this doesn't answer my question
type alias Model =
{ routes : List Route
, hovered : Maybe Int
, selected : Maybe Int
, map : Map.InternalModel
, table : Table.InternalModel
, profile : Profile.InternalModel
}
viewProfile : List Route -> Maybe Int -> InternalModel -> Html Msg
Just break it into modules so your similar functions are grouped together in files. Use them just like you already are.The part I don't understand is: how do you create UI components that maintain their internal state without nesting them as child components?
Is there some public code that shows this pattern in action?
It would be wonderful to look at something that feels like it needs to be split up and see a version that is flat.
Thanks a lot, Richard, it makes much more sense now!
Follow up questions: What do Profile.update and Profile.Msg look like? Also, what kinds of different places do different profiles get updated?
Wayp
ointConf
component.internalUpdate : Msg -> Internal -> Internal
internalUpdate msg model =
case msg of
SliderMsg (Slider.ChangeValue newSpeed) ->
{ model | average_speed = newSpeed }
WaypointConfMsg idx msg' ->
let
newOp : Maybe (WaypointConf.Model {})
newOp =
Maybe.map (WaypointConf.update msg') (Array.get idx model.waypointsConfs
)
in
case newOp of
Nothing ->
model
Just op ->
{ model | operating_points = Array.Extra.update idx (\_ -> op) model.waypointsConfs }
update : Msg -> Model a -> Model a
update msg model =
let
newInternal : Internal
newInternal =
internalUpdate msg <| toInternal model
in
case msg of
SliderMsg (Slider.ChangeValue newSpeed) ->
{ model | profile = newInternal, shared = Trip.setAverageSpeed model.shared newSpeed }
WaypointConf
Msg idx msg' ->
case msg' of
WaypointConf
.ChangeDateOrTime _ ->
{ model | profile = newInternal, shared = Trip.changeOpDate model.shared idx <| getDate idx model newInternal }
WaypointConf.SameDateAndTime _ ->
{ model | profile = newInternal }
Wayp
ointConf
which contains the message itself and the index of the waypoint it applies to. It looks like this:type Msg =
WaypointConfMsg Int WaypointConf.Msg
| SliderMsg Slider.Msg
WaypointConf
Msg idx msg' ->WaypointConf
.ChangeDateOrTime _ ->